-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfindMTX.go
210 lines (179 loc) · 5.14 KB
/
findMTX.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
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
package main
import (
"bufio"
"fmt"
"github.com/BurntSushi/toml"
"io/ioutil"
"os"
"errors"
"strings"
"time"
"github.com/jogi1/poe"
)
type Config struct {
AccountName string
Email string
Password string
SessionId string
StashLeagues []string
DelayTime time.Duration
}
func removeNameStuff(name string) string {
splits := strings.Split(name, ">>")
return splits[len(splits)-1]
}
func displayStartupError(message error) {
reader := bufio.NewReader(os.Stdin)
fmt.Println(message)
fmt.Println("Press enter to close this window.")
reader.ReadString('\n')
}
func loadConfig() (config Config, err error) {
var conf Config
tomlData, err := ioutil.ReadFile("config")
if err != nil {
return conf, errors.New("could not open config file")
}
if _, err := toml.Decode(string(tomlData), &conf); err != nil {
// handle error
return conf, err
}
if len(conf.AccountName) == 0 {
return conf, errors.New("need an AccountName")
}
if len(conf.SessionId) == 0 {
if len(conf.Email) == 0 {
return conf, errors.New("need Email/Password if no SessionId is provided")
}
if len(conf.Password) == 0 {
return conf, errors.New("need Email/Password if no SessionId is provided")
}
}
return conf, nil
}
func printCharName (name string, league string) {
s := fmt.Sprintf("%v in League %v", name, league)
fmt.Printf("\r%v%*v\n", s, 60 - len(s), " ")
}
func poeFindCharacterMTX (p *poe.Poe, conf Config) {
characters, err := p.GetCharacters()
if err != nil {
displayStartupError(err)
return
}
for index, character := range characters {
var charNamePrinted = bool(false)
fmt.Printf("\r%60v", " ")
s := fmt.Sprintf("Checking %2v/%2v (%v) in League (%v)", index +1, len(characters), character.Name, character.League)
fmt.Printf("\r%v%*v", s, 60 - len(s), " ")
charItems, err := p.GetCharacterItems(character.Name)
if err != nil {
displayStartupError(err)
return
}
for _, item := range charItems.Items {
if len(item.CosmeticMods) > 0 {
if !charNamePrinted {
charNamePrinted = true
printCharName(character.Name, character.League)
}
fmt.Printf("\t %v (%v)-> %v\n", removeNameStuff(item.Name), item.TypeLine, item.CosmeticMods)
}
for _, socketedItem := range item.SocketedItems {
if len(socketedItem.CosmeticMods) > 0 {
if !charNamePrinted {
charNamePrinted = true
printCharName(character.Name, character.League)
}
fmt.Printf("\t %v (%v)-> %v socketed in (%v - %v)\n", removeNameStuff(socketedItem.Name), socketedItem.TypeLine, socketedItem.CosmeticMods, removeNameStuff(item.Name), item.TypeLine)
}
}
}
}
fmt.Printf("\r%*v\n", 60, " ")
}
func printStashCount(league string, stashtab string, index int, max int) {
s := fmt.Sprintf("%v %2v/%2v - %v", league, index + 1, max, stashtab)
fmt.Printf("\r%v%*v", s, 60 - len(s), " ")
}
func printTab(league string, stash string) {
s := fmt.Sprintf("%v - %v", league, stash)
fmt.Printf("\r%v%*v\n", s, 60 - len(s), " ")
}
func printItem(item poe.Item) {
fmt.Printf("\t%v (%v) (%v|%v) -> %v\n", removeNameStuff(item.Name), item.TypeLine, item.X + 1, item.Y + 1, item.CosmeticMods)
}
func printSocketedItem(item poe.Item, parent poe.Item) {
fmt.Printf("\t%v (%v|%v) -> %v socketed in %v (%v) (%v|%v)\n", item.TypeLine, item.X + 1, item.Y + 1, item.CosmeticMods, removeNameStuff(parent.Name), parent.TypeLine, parent.X +1, parent.Y+1)
}
func poeFindStashMTX(p *poe.Poe, conf Config) {
// getting stash
for _, league := range conf.StashLeagues {
var tabNamePrinted = bool(false)
firstTab, err := p.GetStash(league, 0, 1)
if err != nil {
displayStartupError(err)
return
}
if firstTab.NumTabs == 0 {
continue
}
printStashCount(league, firstTab.Tabs[0].N, 0, firstTab.NumTabs)
time.Sleep(1000 * time.Millisecond * conf.DelayTime)
for _, item := range firstTab.Items {
if len(item.CosmeticMods) > 0 {
if !tabNamePrinted {
tabNamePrinted = true
printTab(league, firstTab.Tabs[0].N)
}
}
}
for i := 1; i < firstTab.NumTabs; i++ {
currentTab, err := p.GetStash(league, i, 0)
if err != nil {
displayStartupError(err)
return
}
printStashCount(league, firstTab.Tabs[i].N, i, firstTab.NumTabs)
for _, item := range currentTab.Items {
if len(item.CosmeticMods) > 0 {
if !tabNamePrinted {
tabNamePrinted = true
printTab(league, firstTab.Tabs[i].N)
}
printItem(item)
}
for _, socketedItem := range item.SocketedItems {
if len(socketedItem.CosmeticMods) > 0 {
if !tabNamePrinted {
tabNamePrinted = true
printTab(league, firstTab.Tabs[i].N)
}
printSocketedItem(socketedItem, item)
}
}
}
time.Sleep(1000 * time.Millisecond * conf.DelayTime)
}
}
}
func main() {
conf, err := loadConfig()
if err != nil {
displayStartupError(err)
return
}
p := new(poe.Poe)
conf.Email = ""
conf.Password = ""
err = p.Login(conf.AccountName, conf.Email, conf.Password, conf.SessionId)
if err != nil {
displayStartupError(err)
return
}
poeFindCharacterMTX(p, conf)
poeFindStashMTX(p, conf)
reader := bufio.NewReader(os.Stdin)
fmt.Print("Press enter to close this window.\n")
reader.ReadString('\n')
}