From c66f4ba79a336689bf2f18d691dd45bc57c6670c Mon Sep 17 00:00:00 2001 From: shoopea Date: Thu, 21 Jan 2021 16:53:14 +0100 Subject: [PATCH] test --- bot.go | 2 -- job.go | 38 ++++++++++++++++++++++++-------------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/bot.go b/bot.go index 5367a44..ae12edb 100644 --- a/bot.go +++ b/bot.go @@ -865,8 +865,6 @@ func botBrewItem(m *ChatWarsMessage, r *regexp.Regexp) { 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) t := time.Now().UTC().Add(1 * time.Second) _, err = createJob(cacheObjSubType[`job_brew_item`], objJobPriority, m.TGSenderUserID64, 0, t, b) diff --git a/job.go b/job.go index 9cd2509..2624620 100644 --- a/job.go +++ b/job.go @@ -2186,11 +2186,7 @@ func jobBrewItem(j Job) { err = json.Unmarshal(j.Payload, &p) logOnError(err, "jobBrewItem : Unmarshal payload") - fmt.Printf("jobBrewItem : getting in...\n") - if p.Status == 0 { - fmt.Printf("jobBrewItem : Status 0, triggering /me\n") - p.Status = 1 err = setJobPayloadJSON(j.ID64, p) @@ -2201,7 +2197,6 @@ func jobBrewItem(j Job) { clientSendCWMsgDelay(j.UserID64, "/me", 0*time.Second) return } else if p.Status == 1 && j.Trigger != 0 { - fmt.Printf("jobBrewItem : Status 1, triggering /alch\n") m, err := getObjMsg(j.Trigger) logOnError(err, "jobBrewItem : getObjMsg("+strconv.FormatInt(j.Trigger, 10)+")") if err == nil { @@ -2226,23 +2221,17 @@ func jobBrewItem(j Job) { } } } else if p.Status == 2 && j.Trigger != 0 { - fmt.Printf("jobBrewItem : Status 2, computing\n") m, err := getObjMsg(j.Trigger) logOnError(err, "jobBrewItem : getObjMsg("+strconv.FormatInt(j.Trigger, 10)+")") if err == nil { - fmt.Printf("jobBrewItem : Status 2, getting quantities\n") rule, err := getMsgParsingRule(m) logOnError(err, "jobBrewItem : getMsgParsingRule") - fmt.Printf("jobBrewItem : Status 2, msg_type_id : %d\n", rule.MsgTypeID64) if rule.MsgTypeID64 == cacheObjSubType[`msg_alch_stock_ack`] { - _, err = parseSubTypeMessageAlchStockAck(m, rule.re) + cwm, err := parseSubTypeMessageAlchStockAck(m, rule.re) logOnError(err, "jobBrewItem : parseSubTypeMessageAlchStockAck") if err == nil { - fmt.Printf("jobBrewItem : Status 2, calculating mana/item\n") // pre-fill maps with references and quantities 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 if p.ManaNow < p.ManaMax { t := (p.ManaMax - p.ManaNow) / ((p.ManaMax / 250) + 1) @@ -2258,11 +2247,32 @@ func jobBrewItem(j Job) { eta = "0m" } - out = fmt.Sprintf("%3s - %20s - %3d", 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 %3s - %20s - %3d\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{ Type: commandReplyMsg, - Text: fmt.Sprintf("ETA : %s\n%s", eta, out), + Text: out, FromMsgID64: p.MsgID64, FromChatID64: p.ChatID64, ParseMode: cmdParseModeHTML,