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

11
def.go
View File

@ -620,11 +620,12 @@ type JobPayloadCraftAll struct {
}
type JobPayloadAlchAll struct {
MsgID64 int64 `json:"msg_id"`
ChatID64 int64 `json:"chat_id"`
Status int64 `json:"status"`
ManaNow int64 `json:"mana_now"`
ManaMax int64 `json:"mana_max"`
MsgID64 int64 `json:"msg_id"`
ChatID64 int64 `json:"chat_id"`
Status int64 `json:"status"`
ManaNow int64 `json:"mana_now"`
ManaMax int64 `json:"mana_max"`
DealList []ChatWarsExchangeDeal `json:"deals"`
}
type JobPayloadBrewItem struct {

63
job.go
View File

@ -2305,13 +2305,14 @@ func jobBrewItem(j Job) {
func jobAlchAll(j Job) {
var (
p JobPayloadAlchAll
maxManaItems map[int64]int64
maxResItems map[int64]int64
itemsCode map[int64]string
itemInStock, itemInserted bool
eta, out string
list []int64
p JobPayloadAlchAll
maxManaItems map[int64]int64
maxResItems map[int64]int64
totalResItems map[int64]int64
itemsCode map[int64]string
itemInserted bool
eta, out string
list []int64
)
err := setJobStart(j.ID64)
@ -2347,6 +2348,28 @@ func jobAlchAll(j Job) {
err = setJobPayloadJSON(j.ID64, 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_alch_stock_ack`])
setJobCallback(j.ID64, j.UserID64, cacheObjSubType[`msg_busy`])
@ -2355,7 +2378,8 @@ func jobAlchAll(j Job) {
return
}
}
} else if p.Status == 2 && j.Trigger != 0 {
} else if p.Status == 3 && j.Trigger != 0 {
m, err := getObjMsg(j.Trigger)
logOnError(err, "jobAlchAll : getObjMsg("+strconv.FormatInt(j.Trigger, 10)+")")
if err == nil {
@ -2367,8 +2391,17 @@ func jobAlchAll(j Job) {
if err == nil {
maxManaItems = make(map[int64]int64)
maxResItems = make(map[int64]int64)
totalResItems = make(map[int64]int64)
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
muxObjItem.RLock()
for _, o := range objItems {
@ -2379,17 +2412,11 @@ func jobAlchAll(j Job) {
maxResItems[o.ObjID64] = maxManaItems[o.ObjID64]
itemsCode[o.ObjID64] = o.Code
for _, i := range o.Craft.Items {
itemInStock = false
for _, s := range cwm.Stock {
if i.ItemID64 == s.ItemID64 {
itemInStock = true
maxResItems[o.ObjID64] = MinInt64(maxResItems[o.ObjID64], s.Quantity/i.Quantity)
break
}
}
if !itemInStock {
items, itemInStock := totalResItems[i.ItemID64]
if itemInStock {
maxResItems[o.ObjID64] = MinInt64(maxResItems[o.ObjID64], items/i.Quantity)
} else {
fmt.Printf("jobAlchAll : missing %s to brew %s\n", i.Name, o.Names[0])
logOnError(err, "jobAlchAll : Unmarshal payload")
maxResItems[o.ObjID64] = 0
break
}

View File

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