-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathquest.go
60 lines (51 loc) · 1.96 KB
/
quest.go
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
package d2s
import (
"encoding/json"
)
// quest struct will represent any quest in game.
type quest [2]byte
// isCompleted will return a bool, telling us if the quest is completed or not.
// We'll do this by looking at bit 0, if it's set or not.
func (q quest) IsCompleted() bool {
return ((q[0] >> 0) & 1) > 0
}
// isRequirementCompleted will return a bool, telling us if the quest requirement is
// completed, this usually means you have killed the boss demon, or all that is left
// is to collect the reward.
func (q quest) IsRequirementCompleted() bool {
return ((q[0] >> 1) & 1) > 0
}
func (q *quest) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
IsCompleted bool `json:"is_completed"`
IsRequirementCompleted bool `json:"is_requirement_completed"`
}{
IsCompleted: q.IsCompleted(),
IsRequirementCompleted: q.IsRequirementCompleted(),
})
}
// Prison Of Ice quest, this has a certain bit we're interested in to calculate resistances.
// If you have consumed the scroll of resistance you'll get +10 @ res.
type prisonOfIce [2]byte
// isCompleted will return a bool, telling us if the quest is completed or not.
// We'll do this by looking at bit 0, if it's set or not.
func (q prisonOfIce) IsCompleted() bool {
return ((q[0] >> 0) & 1) > 0
}
// isRequirementCompleted will return a bool, telling us if the quest requirement is
// completed, this usually means you have killed the boss demon, or all that is left
// is to collect the reward.
func (q prisonOfIce) IsRequirementCompleted() bool {
return ((q[0] >> 1) & 1) > 0
}
func (q *prisonOfIce) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
IsCompleted bool `json:"is_completed"`
ConsumedScroll bool `json:"consumed_scroll"`
IsRequirementCompleted bool `json:"is_requirement_completed"`
}{
IsCompleted: ((q[0] >> 0) & 1) > 0,
ConsumedScroll: ((q[0] >> 7) & 1) > 0,
IsRequirementCompleted: ((q[0] >> 1) & 1) > 0,
})
}