test alch sorting

This commit is contained in:
shoopea 2020-02-29 19:29:29 +08:00
parent e8d020b475
commit 74b37fc688

33
job.go
View File

@ -2031,11 +2031,13 @@ func jobCraftItem(j Job) {
func jobAlchAll(j Job) {
var (
p JobPayloadAlchAll
maxManaItems map[int64]int64
maxResItems map[int64]int64
itemInStock bool
eta, out string
p JobPayloadAlchAll
maxManaItems map[int64]int64
maxResItems map[int64]int64
itemsCode map[int64]string
itemInStock, itemInserted bool
eta, out string
list []int64
)
err := setJobStart(j.ID64)
@ -2090,6 +2092,7 @@ func jobAlchAll(j Job) {
if err == nil {
maxManaItems = make(map[int64]int64)
maxResItems = make(map[int64]int64)
itemsCode = make(map[int64]string)
// pre-fill maps with references and quantities
muxObjItem.RLock()
@ -2099,6 +2102,7 @@ func jobAlchAll(j Job) {
if rx.MatchString(o.Craft.Command) {
maxManaItems[o.ObjID64] = p.ManaMax / o.Craft.Mana
maxResItems[o.ObjID64] = maxManaItems[o.ObjID64]
itemsCode[o.ObjID64] = o.Code
for _, i := range o.Craft.Items {
itemInStock = false
for _, s := range cwm.Stock {
@ -2131,12 +2135,27 @@ func jobAlchAll(j Job) {
} else {
eta = "0m"
}
list = make([]int64, 0)
for k, q := range maxManaItems {
if q == maxResItems[k] {
o, _ := getObjItem(k)
out = fmt.Sprintf("%s\n<code>%s - %s - %d</code>", out, o.Code, o.Names[0], q)
itemInserted = false
for i, n := range list {
if itemsCode[n] > itemsCode[k] {
itemInserted = true
list = append(list, 0)
copy(list[i+1:], list[i:])
list[i] = k
}
if !itemInserted {
list = append(list, k)
}
}
}
}
for _, i := range list {
o, _ := getObjItem(i)
out = fmt.Sprintf("%s\n<code>%s - %s - %d</code>", out, o.Code, o.Names[0], maxManaItems[i])
}
c := TGCommand{
Type: commandReplyMsg,