This commit is contained in:
shoopea 2021-01-21 16:53:14 +01:00
parent 9b0402d210
commit c66f4ba79a
2 changed files with 24 additions and 16 deletions

2
bot.go
View File

@ -865,8 +865,6 @@ func botBrewItem(m *ChatWarsMessage, r *regexp.Regexp) {
p.ObjItemID64 = getObjItemID(r.ReplaceAllString(m.Text, "${Code}"), "") p.ObjItemID64 = getObjItemID(r.ReplaceAllString(m.Text, "${Code}"), "")
fmt.Printf("Code[%s] : %d\n", r.ReplaceAllString(m.Text, "${Code}"), p.ObjItemID64)
b, _ := json.Marshal(p) b, _ := json.Marshal(p)
t := time.Now().UTC().Add(1 * time.Second) t := time.Now().UTC().Add(1 * time.Second)
_, err = createJob(cacheObjSubType[`job_brew_item`], objJobPriority, m.TGSenderUserID64, 0, t, b) _, err = createJob(cacheObjSubType[`job_brew_item`], objJobPriority, m.TGSenderUserID64, 0, t, b)

38
job.go
View File

@ -2186,11 +2186,7 @@ func jobBrewItem(j Job) {
err = json.Unmarshal(j.Payload, &p) err = json.Unmarshal(j.Payload, &p)
logOnError(err, "jobBrewItem : Unmarshal payload") logOnError(err, "jobBrewItem : Unmarshal payload")
fmt.Printf("jobBrewItem : getting in...\n")
if p.Status == 0 { if p.Status == 0 {
fmt.Printf("jobBrewItem : Status 0, triggering /me\n")
p.Status = 1 p.Status = 1
err = setJobPayloadJSON(j.ID64, p) err = setJobPayloadJSON(j.ID64, p)
@ -2201,7 +2197,6 @@ func jobBrewItem(j Job) {
clientSendCWMsgDelay(j.UserID64, "/me", 0*time.Second) clientSendCWMsgDelay(j.UserID64, "/me", 0*time.Second)
return return
} else if p.Status == 1 && j.Trigger != 0 { } else if p.Status == 1 && j.Trigger != 0 {
fmt.Printf("jobBrewItem : Status 1, triggering /alch\n")
m, err := getObjMsg(j.Trigger) m, err := getObjMsg(j.Trigger)
logOnError(err, "jobBrewItem : getObjMsg("+strconv.FormatInt(j.Trigger, 10)+")") logOnError(err, "jobBrewItem : getObjMsg("+strconv.FormatInt(j.Trigger, 10)+")")
if err == nil { if err == nil {
@ -2226,23 +2221,17 @@ func jobBrewItem(j Job) {
} }
} }
} else if p.Status == 2 && j.Trigger != 0 { } else if p.Status == 2 && j.Trigger != 0 {
fmt.Printf("jobBrewItem : Status 2, computing\n")
m, err := getObjMsg(j.Trigger) m, err := getObjMsg(j.Trigger)
logOnError(err, "jobBrewItem : getObjMsg("+strconv.FormatInt(j.Trigger, 10)+")") logOnError(err, "jobBrewItem : getObjMsg("+strconv.FormatInt(j.Trigger, 10)+")")
if err == nil { if err == nil {
fmt.Printf("jobBrewItem : Status 2, getting quantities\n")
rule, err := getMsgParsingRule(m) rule, err := getMsgParsingRule(m)
logOnError(err, "jobBrewItem : getMsgParsingRule") logOnError(err, "jobBrewItem : getMsgParsingRule")
fmt.Printf("jobBrewItem : Status 2, msg_type_id : %d\n", rule.MsgTypeID64)
if rule.MsgTypeID64 == cacheObjSubType[`msg_alch_stock_ack`] { if rule.MsgTypeID64 == cacheObjSubType[`msg_alch_stock_ack`] {
_, err = parseSubTypeMessageAlchStockAck(m, rule.re) cwm, err := parseSubTypeMessageAlchStockAck(m, rule.re)
logOnError(err, "jobBrewItem : parseSubTypeMessageAlchStockAck") logOnError(err, "jobBrewItem : parseSubTypeMessageAlchStockAck")
if err == nil { if err == nil {
fmt.Printf("jobBrewItem : Status 2, calculating mana/item\n")
// pre-fill maps with references and quantities // pre-fill maps with references and quantities
o, _ := getObjItem(p.ObjItemID64) o, _ := getObjItem(p.ObjItemID64)
fmt.Printf("p.ManaMax : %d\n", p.ManaMax)
fmt.Printf("o.Craft.Mana : %d\n", o.Craft.Mana)
maxManaItems = p.ManaMax / o.Craft.Mana maxManaItems = p.ManaMax / o.Craft.Mana
if p.ManaNow < p.ManaMax { if p.ManaNow < p.ManaMax {
t := (p.ManaMax - p.ManaNow) / ((p.ManaMax / 250) + 1) t := (p.ManaMax - p.ManaNow) / ((p.ManaMax / 250) + 1)
@ -2258,11 +2247,32 @@ func jobBrewItem(j Job) {
eta = "0m" eta = "0m"
} }
out = fmt.Sprintf("<a href=\"https://t.me/share/url?url=/brew_%s %d\">%3s - %20s - %3d</a>", o.Code, maxManaItems, o.Code, o.Names[0], maxManaItems) require := ""
missing := ""
for _, req := range o.Craft.Items {
itemsInStock := 0
for _, stock := range cwm.Stock {
if req.ItemID64 == stock.ItemID64 {
itemsInStock = stock.Quantity
break
}
}
if req.Quantity*maxManaItems > itemsInStock {
missing = fmt.Sprintf("%s %3s - %s [%d]\n", missing, req.Code, req.Name[0], req.Quantity*maxManaItems-itemsInStock)
}
require = fmt.Sprintf("%s %3s - %s [%d]\n", require, req.Code, req.Name[0], req.Quantity*maxManaItems)
}
out = fmt.Sprintf("ETA : %s\n", eta)
out = fmt.Sprintf("Item brewing summary :\n <a href=\"https://t.me/share/url?url=/brew_%s %d\">%3s - %20s - %3d</a>\n", o.Code, maxManaItems, o.Code, o.Names[0], maxManaItems)
out = fmt.Sprintf("%sRequire :\n%s", out, require)
if missing != "" {
out = fmt.Sprintf("%sMissing :\n%s", out, missing)
}
c := TGCommand{ c := TGCommand{
Type: commandReplyMsg, Type: commandReplyMsg,
Text: fmt.Sprintf("ETA : %s\n%s", eta, out), Text: out,
FromMsgID64: p.MsgID64, FromMsgID64: p.MsgID64,
FromChatID64: p.ChatID64, FromChatID64: p.ChatID64,
ParseMode: cmdParseModeHTML, ParseMode: cmdParseModeHTML,