add stex to /alch_all

This commit is contained in:
shoopea 2022-01-20 21:58:54 +08:00
parent 2be2a9774e
commit 72f383662a
4 changed files with 55 additions and 26 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
chirpnest

1
def.go
View File

@ -625,6 +625,7 @@ type JobPayloadAlchAll struct {
Status int64 `json:"status"` Status int64 `json:"status"`
ManaNow int64 `json:"mana_now"` ManaNow int64 `json:"mana_now"`
ManaMax int64 `json:"mana_max"` ManaMax int64 `json:"mana_max"`
DealList []ChatWarsExchangeDeal `json:"deals"`
} }
type JobPayloadBrewItem struct { type JobPayloadBrewItem struct {

51
job.go
View File

@ -2308,8 +2308,9 @@ func jobAlchAll(j Job) {
p JobPayloadAlchAll p JobPayloadAlchAll
maxManaItems map[int64]int64 maxManaItems map[int64]int64
maxResItems map[int64]int64 maxResItems map[int64]int64
totalResItems map[int64]int64
itemsCode map[int64]string itemsCode map[int64]string
itemInStock, itemInserted bool itemInserted bool
eta, out string eta, out string
list []int64 list []int64
) )
@ -2347,6 +2348,28 @@ func jobAlchAll(j Job) {
err = setJobPayloadJSON(j.ID64, p) err = setJobPayloadJSON(j.ID64, p)
logOnError(err, "jobAlchAll : setJobPayloadJSON(p)") logOnError(err, "jobAlchAll : setJobPayloadJSON(p)")
setJobCallback(j.ID64, j.UserID64, cacheObjSubType[`msg_exchange_ack`])
setJobCallback(j.ID64, j.UserID64, cacheObjSubType[`msg_busy`])
rescheduleJob(j.ID64, 0, time.Unix(maxUnixTimestamp, 0).UTC())
clientSendCWMsgDelay(j.UserID64, "/exchange", 2*time.Second)
return
}
}
} else if p.Status == 2 && j.Trigger != 0 {
m, err := getObjMsg(j.Trigger)
logOnError(err, "jobAlchAll : getObjMsg("+strconv.FormatInt(j.Trigger, 10)+")")
if err == nil {
rule, err := getMsgParsingRule(m)
logOnError(err, "jobAlchAll : getMsgParsingRule")
if rule.MsgTypeID64 == cacheObjSubType[`msg_exchange_ack`] {
cwm, err := parseSubTypeMessageExchangeAck(m, rule.re)
p.Status = 3
p.DealList = cwm.DealList
err = setJobPayloadJSON(j.ID64, p)
logOnError(err, "jobAlchAll : setJobPayloadJSON(p)")
setJobCallback(j.ID64, j.UserID64, cacheObjSubType[`msg_skill_too_low`]) setJobCallback(j.ID64, j.UserID64, cacheObjSubType[`msg_skill_too_low`])
setJobCallback(j.ID64, j.UserID64, cacheObjSubType[`msg_alch_stock_ack`]) setJobCallback(j.ID64, j.UserID64, cacheObjSubType[`msg_alch_stock_ack`])
setJobCallback(j.ID64, j.UserID64, cacheObjSubType[`msg_busy`]) setJobCallback(j.ID64, j.UserID64, cacheObjSubType[`msg_busy`])
@ -2355,7 +2378,8 @@ func jobAlchAll(j Job) {
return return
} }
} }
} else if p.Status == 2 && j.Trigger != 0 {
} else if p.Status == 3 && j.Trigger != 0 {
m, err := getObjMsg(j.Trigger) m, err := getObjMsg(j.Trigger)
logOnError(err, "jobAlchAll : getObjMsg("+strconv.FormatInt(j.Trigger, 10)+")") logOnError(err, "jobAlchAll : getObjMsg("+strconv.FormatInt(j.Trigger, 10)+")")
if err == nil { if err == nil {
@ -2367,8 +2391,17 @@ func jobAlchAll(j Job) {
if err == nil { if err == nil {
maxManaItems = make(map[int64]int64) maxManaItems = make(map[int64]int64)
maxResItems = make(map[int64]int64) maxResItems = make(map[int64]int64)
totalResItems = make(map[int64]int64)
itemsCode = make(map[int64]string) itemsCode = make(map[int64]string)
// fill from alch+stex
for _, s := range cwm.Stock {
totalResItems[s.ItemID64] = s.Quantity
}
for _, d := range p.DealList {
totalResItems[d.ItemID64] = totalResItems[d.ItemID64] + d.Quantity
}
// pre-fill maps with references and quantities // pre-fill maps with references and quantities
muxObjItem.RLock() muxObjItem.RLock()
for _, o := range objItems { for _, o := range objItems {
@ -2379,17 +2412,11 @@ func jobAlchAll(j Job) {
maxResItems[o.ObjID64] = maxManaItems[o.ObjID64] maxResItems[o.ObjID64] = maxManaItems[o.ObjID64]
itemsCode[o.ObjID64] = o.Code itemsCode[o.ObjID64] = o.Code
for _, i := range o.Craft.Items { for _, i := range o.Craft.Items {
itemInStock = false items, itemInStock := totalResItems[i.ItemID64]
for _, s := range cwm.Stock { if itemInStock {
if i.ItemID64 == s.ItemID64 { maxResItems[o.ObjID64] = MinInt64(maxResItems[o.ObjID64], items/i.Quantity)
itemInStock = true } else {
maxResItems[o.ObjID64] = MinInt64(maxResItems[o.ObjID64], s.Quantity/i.Quantity)
break
}
}
if !itemInStock {
fmt.Printf("jobAlchAll : missing %s to brew %s\n", i.Name, o.Names[0]) fmt.Printf("jobAlchAll : missing %s to brew %s\n", i.Name, o.Names[0])
logOnError(err, "jobAlchAll : Unmarshal payload")
maxResItems[o.ObjID64] = 0 maxResItems[o.ObjID64] = 0
break break
} }

View File

@ -1,5 +1,5 @@
// Code generated by version.sh (@generated) DO NOT EDIT. // Code generated by version.sh (@generated) DO NOT EDIT.
package main package main
var githash = "f9a4523" var githash = "2be2a97"
var buildstamp = "2021-10-28_11:35:58" var buildstamp = "2022-01-20_13:57:12"
var commits = "2554" var commits = "2555"