wow_world_base 0.3.0

Base definitions and functions for World of Warcraft game servers
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
/// Auto generated from the original `wowm` in file [`wow_message_parser/wowm/world/queries/smsg_item_query_single_response.wowm:112`](https://github.com/gtker/wow_messages/tree/main/wow_message_parser/wowm/world/queries/smsg_item_query_single_response.wowm#L112):
/// ```text
/// flag ItemFlag : u32 {
///     NONE = 0x00000000;
///     NO_PICKUP = 0x00000001;
///     CONJURED = 0x00000002;
///     LOOTABLE = 0x00000004;
///     DEPRECATED = 0x00000010;
///     INDESTRUCTIBLE = 0x00000020;
///     PLAYER_CAST = 0x00000040;
///     NO_EQUIP_COOLDOWN = 0x00000080;
///     INT_BONUS_INSTEAD = 0x00000100;
///     WRAPPER = 0x00000200;
///     IGNORE_BAG_SPACE = 0x00000400;
///     PARTY_LOOT = 0x00000800;
///     CHARTER = 0x00002000;
///     HAS_TEXT = 0x00004000;
///     NO_DISENCHANT = 0x00008000;
///     REAL_DURATION = 0x00010000;
///     NO_CREATOR = 0x00020000;
/// }
/// ```
#[derive(Debug, PartialEq, Eq, Hash, Ord, PartialOrd, Copy, Clone, Default)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "serde", serde(transparent))]
pub struct ItemFlag {
    inner: u32,
}

#[cfg(feature = "print-testcase")]
impl ItemFlag {
    #[allow(clippy::missing_const_for_fn)]
    pub fn as_test_case_value(&self) -> String {
        let mut s = String::new();
        let mut first = true;
        if self.is_empty() {
            use std::fmt::Write;
            if !first {
                write!(s, " | ").unwrap();
            }
            write!(s, "NONE").unwrap();
            first = false;
        }
        if self.is_no_pickup() {
            use std::fmt::Write;
            if !first {
                write!(s, " | ").unwrap();
            }
            write!(s, "NO_PICKUP").unwrap();
            first = false;
        }
        if self.is_conjured() {
            use std::fmt::Write;
            if !first {
                write!(s, " | ").unwrap();
            }
            write!(s, "CONJURED").unwrap();
            first = false;
        }
        if self.is_lootable() {
            use std::fmt::Write;
            if !first {
                write!(s, " | ").unwrap();
            }
            write!(s, "LOOTABLE").unwrap();
            first = false;
        }
        if self.is_deprecated() {
            use std::fmt::Write;
            if !first {
                write!(s, " | ").unwrap();
            }
            write!(s, "DEPRECATED").unwrap();
            first = false;
        }
        if self.is_indestructible() {
            use std::fmt::Write;
            if !first {
                write!(s, " | ").unwrap();
            }
            write!(s, "INDESTRUCTIBLE").unwrap();
            first = false;
        }
        if self.is_player_cast() {
            use std::fmt::Write;
            if !first {
                write!(s, " | ").unwrap();
            }
            write!(s, "PLAYER_CAST").unwrap();
            first = false;
        }
        if self.is_no_equip_cooldown() {
            use std::fmt::Write;
            if !first {
                write!(s, " | ").unwrap();
            }
            write!(s, "NO_EQUIP_COOLDOWN").unwrap();
            first = false;
        }
        if self.is_int_bonus_instead() {
            use std::fmt::Write;
            if !first {
                write!(s, " | ").unwrap();
            }
            write!(s, "INT_BONUS_INSTEAD").unwrap();
            first = false;
        }
        if self.is_wrapper() {
            use std::fmt::Write;
            if !first {
                write!(s, " | ").unwrap();
            }
            write!(s, "WRAPPER").unwrap();
            first = false;
        }
        if self.is_ignore_bag_space() {
            use std::fmt::Write;
            if !first {
                write!(s, " | ").unwrap();
            }
            write!(s, "IGNORE_BAG_SPACE").unwrap();
            first = false;
        }
        if self.is_party_loot() {
            use std::fmt::Write;
            if !first {
                write!(s, " | ").unwrap();
            }
            write!(s, "PARTY_LOOT").unwrap();
            first = false;
        }
        if self.is_charter() {
            use std::fmt::Write;
            if !first {
                write!(s, " | ").unwrap();
            }
            write!(s, "CHARTER").unwrap();
            first = false;
        }
        if self.is_has_text() {
            use std::fmt::Write;
            if !first {
                write!(s, " | ").unwrap();
            }
            write!(s, "HAS_TEXT").unwrap();
            first = false;
        }
        if self.is_no_disenchant() {
            use std::fmt::Write;
            if !first {
                write!(s, " | ").unwrap();
            }
            write!(s, "NO_DISENCHANT").unwrap();
            first = false;
        }
        if self.is_real_duration() {
            use std::fmt::Write;
            if !first {
                write!(s, " | ").unwrap();
            }
            write!(s, "REAL_DURATION").unwrap();
            first = false;
        }
        if self.is_no_creator() {
            use std::fmt::Write;
            if !first {
                write!(s, " | ").unwrap();
            }
            write!(s, "NO_CREATOR").unwrap();
            first = false;
        }
        s
    }

}

impl ItemFlag {
    pub const fn new(inner: u32) -> Self {
        Self { inner }
    }

    pub const NONE: u32 = 0x00;
    pub const NO_PICKUP: u32 = 0x01;
    pub const CONJURED: u32 = 0x02;
    pub const LOOTABLE: u32 = 0x04;
    pub const DEPRECATED: u32 = 0x10;
    pub const INDESTRUCTIBLE: u32 = 0x20;
    pub const PLAYER_CAST: u32 = 0x40;
    pub const NO_EQUIP_COOLDOWN: u32 = 0x80;
    pub const INT_BONUS_INSTEAD: u32 = 0x100;
    pub const WRAPPER: u32 = 0x200;
    pub const IGNORE_BAG_SPACE: u32 = 0x400;
    pub const PARTY_LOOT: u32 = 0x800;
    pub const CHARTER: u32 = 0x2000;
    pub const HAS_TEXT: u32 = 0x4000;
    pub const NO_DISENCHANT: u32 = 0x8000;
    pub const REAL_DURATION: u32 = 0x10000;
    pub const NO_CREATOR: u32 = 0x20000;

    pub const fn empty() -> Self {
        Self { inner: 0 }
    }

    pub const fn is_empty(&self) -> bool {
        self.inner == 0
    }

    pub const fn all() -> Self {
        Self {
            inner: Self::NONE
                | Self::NO_PICKUP
                | Self::CONJURED
                | Self::LOOTABLE
                | Self::DEPRECATED
                | Self::INDESTRUCTIBLE
                | Self::PLAYER_CAST
                | Self::NO_EQUIP_COOLDOWN
                | Self::INT_BONUS_INSTEAD
                | Self::WRAPPER
                | Self::IGNORE_BAG_SPACE
                | Self::PARTY_LOOT
                | Self::CHARTER
                | Self::HAS_TEXT
                | Self::NO_DISENCHANT
                | Self::REAL_DURATION
                | Self::NO_CREATOR
        }
    }

    pub const fn is_no_pickup(&self) -> bool {
        (self.inner & Self::NO_PICKUP) != 0
    }

    /// not used
    pub const fn new_no_pickup() -> Self {
        Self { inner: Self::NO_PICKUP }
    }

    pub fn set_no_pickup(&mut self) -> Self {
        self.inner |= Self::NO_PICKUP;
        *self
    }

    pub fn clear_no_pickup(&mut self) -> Self {
        self.inner &= Self::NO_PICKUP.reverse_bits();
        *self
    }

    pub const fn is_conjured(&self) -> bool {
        (self.inner & Self::CONJURED) != 0
    }

    pub const fn new_conjured() -> Self {
        Self { inner: Self::CONJURED }
    }

    pub fn set_conjured(&mut self) -> Self {
        self.inner |= Self::CONJURED;
        *self
    }

    pub fn clear_conjured(&mut self) -> Self {
        self.inner &= Self::CONJURED.reverse_bits();
        *self
    }

    pub const fn is_lootable(&self) -> bool {
        (self.inner & Self::LOOTABLE) != 0
    }

    /// affect only non container items that can be 'open' for loot. It or lockid set enable for client show 'Right click to open'. See also `ITEM_DYNFLAG_UNLOCKED`
    pub const fn new_lootable() -> Self {
        Self { inner: Self::LOOTABLE }
    }

    pub fn set_lootable(&mut self) -> Self {
        self.inner |= Self::LOOTABLE;
        *self
    }

    pub fn clear_lootable(&mut self) -> Self {
        self.inner &= Self::LOOTABLE.reverse_bits();
        *self
    }

    pub const fn is_deprecated(&self) -> bool {
        (self.inner & Self::DEPRECATED) != 0
    }

    /// can't repeat old note: appears red icon (like when item durability==0)
    pub const fn new_deprecated() -> Self {
        Self { inner: Self::DEPRECATED }
    }

    pub fn set_deprecated(&mut self) -> Self {
        self.inner |= Self::DEPRECATED;
        *self
    }

    pub fn clear_deprecated(&mut self) -> Self {
        self.inner &= Self::DEPRECATED.reverse_bits();
        *self
    }

    pub const fn is_indestructible(&self) -> bool {
        (self.inner & Self::INDESTRUCTIBLE) != 0
    }

    /// used for totem. Item can not be destroyed, except by using spell (item can be reagent for spell and then allowed)
    pub const fn new_indestructible() -> Self {
        Self { inner: Self::INDESTRUCTIBLE }
    }

    pub fn set_indestructible(&mut self) -> Self {
        self.inner |= Self::INDESTRUCTIBLE;
        *self
    }

    pub fn clear_indestructible(&mut self) -> Self {
        self.inner &= Self::INDESTRUCTIBLE.reverse_bits();
        *self
    }

    pub const fn is_player_cast(&self) -> bool {
        (self.inner & Self::PLAYER_CAST) != 0
    }

    /// ? old note: usable
    pub const fn new_player_cast() -> Self {
        Self { inner: Self::PLAYER_CAST }
    }

    pub fn set_player_cast(&mut self) -> Self {
        self.inner |= Self::PLAYER_CAST;
        *self
    }

    pub fn clear_player_cast(&mut self) -> Self {
        self.inner &= Self::PLAYER_CAST.reverse_bits();
        *self
    }

    pub const fn is_no_equip_cooldown(&self) -> bool {
        (self.inner & Self::NO_EQUIP_COOLDOWN) != 0
    }

    pub const fn new_no_equip_cooldown() -> Self {
        Self { inner: Self::NO_EQUIP_COOLDOWN }
    }

    pub fn set_no_equip_cooldown(&mut self) -> Self {
        self.inner |= Self::NO_EQUIP_COOLDOWN;
        *self
    }

    pub fn clear_no_equip_cooldown(&mut self) -> Self {
        self.inner &= Self::NO_EQUIP_COOLDOWN.reverse_bits();
        *self
    }

    pub const fn is_int_bonus_instead(&self) -> bool {
        (self.inner & Self::INT_BONUS_INSTEAD) != 0
    }

    pub const fn new_int_bonus_instead() -> Self {
        Self { inner: Self::INT_BONUS_INSTEAD }
    }

    pub fn set_int_bonus_instead(&mut self) -> Self {
        self.inner |= Self::INT_BONUS_INSTEAD;
        *self
    }

    pub fn clear_int_bonus_instead(&mut self) -> Self {
        self.inner &= Self::INT_BONUS_INSTEAD.reverse_bits();
        *self
    }

    pub const fn is_wrapper(&self) -> bool {
        (self.inner & Self::WRAPPER) != 0
    }

    /// used or not used wrapper
    pub const fn new_wrapper() -> Self {
        Self { inner: Self::WRAPPER }
    }

    pub fn set_wrapper(&mut self) -> Self {
        self.inner |= Self::WRAPPER;
        *self
    }

    pub fn clear_wrapper(&mut self) -> Self {
        self.inner &= Self::WRAPPER.reverse_bits();
        *self
    }

    pub const fn is_ignore_bag_space(&self) -> bool {
        (self.inner & Self::IGNORE_BAG_SPACE) != 0
    }

    /// ignore bag space at new item creation?
    pub const fn new_ignore_bag_space() -> Self {
        Self { inner: Self::IGNORE_BAG_SPACE }
    }

    pub fn set_ignore_bag_space(&mut self) -> Self {
        self.inner |= Self::IGNORE_BAG_SPACE;
        *self
    }

    pub fn clear_ignore_bag_space(&mut self) -> Self {
        self.inner &= Self::IGNORE_BAG_SPACE.reverse_bits();
        *self
    }

    pub const fn is_party_loot(&self) -> bool {
        (self.inner & Self::PARTY_LOOT) != 0
    }

    /// determines if item is party loot or not
    pub const fn new_party_loot() -> Self {
        Self { inner: Self::PARTY_LOOT }
    }

    pub fn set_party_loot(&mut self) -> Self {
        self.inner |= Self::PARTY_LOOT;
        *self
    }

    pub fn clear_party_loot(&mut self) -> Self {
        self.inner &= Self::PARTY_LOOT.reverse_bits();
        *self
    }

    pub const fn is_charter(&self) -> bool {
        (self.inner & Self::CHARTER) != 0
    }

    /// guild charter
    pub const fn new_charter() -> Self {
        Self { inner: Self::CHARTER }
    }

    pub fn set_charter(&mut self) -> Self {
        self.inner |= Self::CHARTER;
        *self
    }

    pub fn clear_charter(&mut self) -> Self {
        self.inner &= Self::CHARTER.reverse_bits();
        *self
    }

    pub const fn is_has_text(&self) -> bool {
        (self.inner & Self::HAS_TEXT) != 0
    }

    /// Only readable items have this (but not all)
    pub const fn new_has_text() -> Self {
        Self { inner: Self::HAS_TEXT }
    }

    pub fn set_has_text(&mut self) -> Self {
        self.inner |= Self::HAS_TEXT;
        *self
    }

    pub fn clear_has_text(&mut self) -> Self {
        self.inner &= Self::HAS_TEXT.reverse_bits();
        *self
    }

    pub const fn is_no_disenchant(&self) -> bool {
        (self.inner & Self::NO_DISENCHANT) != 0
    }

    pub const fn new_no_disenchant() -> Self {
        Self { inner: Self::NO_DISENCHANT }
    }

    pub fn set_no_disenchant(&mut self) -> Self {
        self.inner |= Self::NO_DISENCHANT;
        *self
    }

    pub fn clear_no_disenchant(&mut self) -> Self {
        self.inner &= Self::NO_DISENCHANT.reverse_bits();
        *self
    }

    pub const fn is_real_duration(&self) -> bool {
        (self.inner & Self::REAL_DURATION) != 0
    }

    pub const fn new_real_duration() -> Self {
        Self { inner: Self::REAL_DURATION }
    }

    pub fn set_real_duration(&mut self) -> Self {
        self.inner |= Self::REAL_DURATION;
        *self
    }

    pub fn clear_real_duration(&mut self) -> Self {
        self.inner &= Self::REAL_DURATION.reverse_bits();
        *self
    }

    pub const fn is_no_creator(&self) -> bool {
        (self.inner & Self::NO_CREATOR) != 0
    }

    pub const fn new_no_creator() -> Self {
        Self { inner: Self::NO_CREATOR }
    }

    pub fn set_no_creator(&mut self) -> Self {
        self.inner |= Self::NO_CREATOR;
        *self
    }

    pub fn clear_no_creator(&mut self) -> Self {
        self.inner &= Self::NO_CREATOR.reverse_bits();
        *self
    }

    pub const fn as_int(&self) -> u32 {
        self.inner
    }

}

impl std::fmt::UpperHex for ItemFlag {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        std::fmt::UpperHex::fmt(&self.inner, f)
    }
}

impl std::fmt::LowerHex for ItemFlag {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        std::fmt::LowerHex::fmt(&self.inner, f)
    }
}

impl std::fmt::Octal for ItemFlag {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        std::fmt::Octal::fmt(&self.inner, f)
    }
}

impl std::fmt::Binary for ItemFlag {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        std::fmt::Binary::fmt(&self.inner, f)
    }
}

impl std::ops::BitAnd for ItemFlag {
    type Output = Self;
    fn bitand(self, rhs: Self) -> Self::Output {
        Self { inner: self.inner.bitand(rhs.inner), }
    }
}

impl std::ops::BitAndAssign for ItemFlag {
    fn bitand_assign(&mut self, rhs: Self) {
        self.inner.bitand_assign(rhs.inner)
    }
}

impl std::ops::BitOr for ItemFlag {
    type Output = Self;
    fn bitor(self, rhs: Self) -> Self::Output {
        Self { inner: self.inner.bitor(rhs.inner), }
    }
}

impl std::ops::BitOrAssign for ItemFlag {
    fn bitor_assign(&mut self, rhs: Self) {
        self.inner.bitor_assign(rhs.inner)
    }
}

impl std::ops::BitXor for ItemFlag {
    type Output = Self;
    fn bitxor(self, rhs: Self) -> Self::Output {
        Self { inner: self.inner.bitxor(rhs.inner), }
    }
}

impl std::ops::BitXorAssign for ItemFlag {
    fn bitxor_assign(&mut self, rhs: Self) {
        self.inner.bitxor_assign(rhs.inner)
    }
}

impl From<u32> for ItemFlag {
    fn from(value: u32) -> Self {
        Self::new(value)
    }
}

impl From<u8> for ItemFlag {
    fn from(value: u8) -> Self {
        Self::new(value.into())
    }
}

impl From<u16> for ItemFlag {
    fn from(value: u16) -> Self {
        Self::new(value.into())
    }
}

impl TryFrom<u64> for ItemFlag {
    type Error = u64;
    fn try_from(value: u64) -> Result<Self, Self::Error> {
        let a = TryInto::<u32>::try_into(value).ok().ok_or(value)?;
        Ok(Self::new(a))
    }
}

impl TryFrom<i8> for ItemFlag {
    type Error = i8;
    fn try_from(value: i8) -> Result<Self, Self::Error> {
        let v = u8::from_le_bytes(value.to_le_bytes());
        Ok(Self::new(v.into()))
    }
}

impl TryFrom<i16> for ItemFlag {
    type Error = i16;
    fn try_from(value: i16) -> Result<Self, Self::Error> {
        let v = u16::from_le_bytes(value.to_le_bytes());
        Ok(Self::new(v.into()))
    }
}

impl From<i32> for ItemFlag {
    fn from(value: i32) -> Self {
        Self::new(u32::from_le_bytes(value.to_le_bytes()))
    }
}

impl TryFrom<i64> for ItemFlag {
    type Error = i64;
    fn try_from(value: i64) -> Result<Self, Self::Error> {
        let v = u64::from_le_bytes(value.to_le_bytes());
        let a = TryInto::<u32>::try_into(v).ok().ok_or(value)?;
        Ok(Self::new(a))
    }
}

impl TryFrom<usize> for ItemFlag {
    type Error = usize;
    fn try_from(value: usize) -> Result<Self, Self::Error> {
        let a = TryInto::<u32>::try_into(value).ok().ok_or(value)?;
        Ok(Self::new(a))
    }
}