forked from Fluorohydride/ygopro-core
-
Notifications
You must be signed in to change notification settings - Fork 4
/
card_data.h
76 lines (67 loc) · 1.46 KB
/
card_data.h
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
#ifndef CARD_DATA_H_
#define CARD_DATA_H_
#include "common.h"
constexpr int CARD_ARTWORK_VERSIONS_OFFSET = 20;
constexpr int SIZE_SETCODE = 16;
constexpr int CARD_BLACK_LUSTER_SOLDIER2 = 5405695;
struct card_data {
uint32 code{};
uint32 alias{};
uint16_t setcode[SIZE_SETCODE]{};
uint32 type{};
uint32 level{};
uint32 attribute{};
uint32 race{};
int32 attack{};
int32 defense{};
uint32 lscale{};
uint32 rscale{};
uint32 link_marker{};
void clear() {
code = 0;
alias = 0;
for (auto& x : setcode)
x = 0;
type = 0;
level = 0;
attribute = 0;
race = 0;
attack = 0;
defense = 0;
lscale = 0;
rscale = 0;
link_marker = 0;
}
bool is_setcode(uint32 value) const {
uint16_t settype = value & 0x0fff;
uint16_t setsubtype = value & 0xf000;
for (auto& x : setcode) {
if ((x & 0x0fff) == settype && (x & 0xf000 & setsubtype) == setsubtype)
return true;
if (!x)
return false;
}
return false;
}
bool is_alternative() const {
if (code == CARD_BLACK_LUSTER_SOLDIER2)
return false;
return alias && (alias < code + CARD_ARTWORK_VERSIONS_OFFSET) && (code < alias + CARD_ARTWORK_VERSIONS_OFFSET);
}
void set_setcode(uint64 value) {
int ctr = 0;
while (value) {
if (value & 0xffff) {
setcode[ctr] = value & 0xffff;
++ctr;
}
value >>= 16;
}
for (int i = ctr; i < SIZE_SETCODE; ++i)
setcode[i] = 0;
}
uint32 get_original_code() const {
return is_alternative() ? alias : code;
}
};
#endif /* CARD_DATA_H_ */