draft alch all

This commit is contained in:
shoopea 2020-02-29 18:22:39 +08:00
parent 385b99d688
commit 55f9f8c81e
2 changed files with 65 additions and 14 deletions

2
def.go
View File

@ -590,7 +590,7 @@ type JobPayloadAlchAll struct {
MsgID64 int64 `json:"msg_id"`
ChatID64 int64 `json:"chat_id"`
Status int64 `json:"status"`
Mana int64 `json:"mana"`
ManaNow int64 `json:"mana_now"`
ManaMax int64 `json:"mana_max"`
}

77
job.go
View File

@ -2030,7 +2030,12 @@ func jobCraftItem(j Job) {
}
func jobAlchAll(j Job) {
var p JobPayloadAlchAll
var (
p JobPayloadAlchAll
maxManaItems map[int64]int64
maxResItems map[int64]int64
itemInStock bool
)
err := setJobStart(j.ID64)
logOnError(err, "jobAlchAll : setJobStart")
@ -2079,20 +2084,66 @@ func jobAlchAll(j Job) {
rule, err := getMsgParsingRule(m)
logOnError(err, "jobAlchAll : getMsgParsingRule")
if rule.MsgTypeID64 == cacheObjSubType[`msg_alch_stock_ack`] {
cwm, err := parseSubTypeMessageAlchStockAck(m, rule)
logOnError(err, "jobAlchAll : parseSubTypeMessageAlchStockAck")
if err == nil {
maxManaItems = make(map[int64]int64)
maxResItems = make(map[int64]int64)
c := TGCommand{
Type: commandReplyMsg,
Text: "Success.",
FromMsgID64: p.MsgID64,
FromChatID64: p.ChatID64,
ParseMode: cmdParseModeHTML,
// pre-fill maps with references and quantities
muxObjItem.RLock()
for _, o := range objItems {
if (o.ItemTypeID == cacheObjSubType[`item_misc`] || o.ItemTypeID == cacheObjSubType[`item_misc`]) && o.Craftable && o.Craft != nil {
rx := regexp.MustCompile("\/brew.*")
if rx.MatchString(o.Craft.Command) {
maxManaItems[o.ObjID64] = p.ManaMax / o.Craft.Mana
maxResItems[o.ObjID64] = maxManaItems[o.ObjID64]
for _, i := range o.Craft.Items {
itemInStock = false
for _, s := range cwm.Stock {
if i.ItemID64 == s.ItemID64 {
itemInStock = true
maxResItems[o.ObjID64] = MaxInt64(maxResItems[o.ObjID64], s.Quantity/i.Quantity)
break
}
}
if !itemInStock {
maxResItems[o.ObjID64] = 0
break
}
}
log.Printf("jobAlchAll : Item %d => Max : %d/%d\n", o.ObjID64, maxResItems[o.ObjID64], maxManaItems[o.ObjID64])
}
}
}
muxObjItem.RUnlock()
var eta string
if p.ManaNow < p.ManaMax {
t := (p.ManaMax - p.ManaNow) / ((p.ManaMax / 250) + 1)
d := time.Duration(t) * time.Minute
if d.Hours() > 1 {
eta = fmt.Sprintf("%s%.0fh", eta, d.Hours())
}
d = d - d.Truncate(1*time.Hour)
if d.Minutes() > 0 {
eta = fmt.Sprintf("%s%.0fm", eta, d.Minutes())
}
}
c := TGCommand{
Type: commandReplyMsg,
Text: "Success.",
FromMsgID64: p.MsgID64,
FromChatID64: p.ChatID64,
ParseMode: cmdParseModeHTML,
}
TGCmdQueue <- c
err = setJobDone(j.ID64)
logOnError(err, "jobAlchAll : setJobDone")
return
}
TGCmdQueue <- c
err = setJobDone(j.ID64)
logOnError(err, "jobAlchAll : setJobDone")
return
}
}
}