update craft all

This commit is contained in:
shoopea 2020-01-29 22:56:19 +08:00
parent 8d5ce121b1
commit 47c855297f
2 changed files with 102 additions and 0 deletions

100
job.go
View File

@ -1897,6 +1897,106 @@ func jobCraftItem(j Job) {
}
func jobCraftAll(j Job) {
var (
p JobPayloadCraftAll
p2 JobPayloadGetVault
b []byte
requiredItems map[string]int64
missingItems map[string]int64
availableItems map[string]int64
)
err := setJobStart(j.ID64)
logOnError(err, "jobCraftAll : setJobStart")
err = json.Unmarshal(j.Payload, &p)
logOnError(err, "jobCraftAll : Unmarshal payload")
if p.Status == 0 {
p2.JobCallbackID64 = j.ID64
p2.ItemTypeList = make([]int64, 0)
p2.ItemTypeList = append(p2.ItemTypeList, cacheObjSubType[`item_recipe`])
p2.ItemTypeList = append(p2.ItemTypeList, cacheObjSubType[`item_part`])
b, err = json.Marshal(p2)
logOnError(err, "jobCraftAll : Marshal(p2)")
jobID64, err := createJob(cacheObjSubType[`job_get_vault`], objJobPriority, j.UserID64, 0, time.Now().UTC(), b)
p.Status = 1
p.VaultJobID64 = jobID64
b, err = json.Marshal(p)
logOnError(err, "jobCraftAll : Marshal(p)")
err = setJobPayloadJSON(j.ID64, p)
logOnError(err, "jobCraftAll : setJobPayloadJSON(p)")
rescheduleJob(j.ID64, 0, time.Unix(maxUnixTimestamp, 0).UTC())
return
}
b = getJobPayload(p.VaultJobID64)
err = json.Unmarshal(b, &p2)
logOnError(err, "jobCraftAll : Unmarshal(p2)")
availableItems = make(map[string]int64)
requiredItems = make(map[string]int64)
missingItems = make(map[string]int64)
craftItems = make(map[string]int64)
totalMana = item.Craft.Mana * p.Quantity
muxObjItem.RLock()
defer muxObjItem.RUnlock()
for _, v := range objItems {
if v.ItemTypeID == cacheObjSubType[`item_other`] {
}
}
/* we can finish the job */
out := fmt.Sprintf("<code>Summary for %d %s\n", p.Quantity, item.Names[0])
out = fmt.Sprintf("%s Mana : %d\n", out, totalMana)
out = fmt.Sprintf("%s Items :\n", out)
for k, v := range requiredItems {
obj, _ := getObjItem(getObjItemID(k, ``))
ava, _ := availableItems[k]
out = fmt.Sprintf("%s [%s] %s : %d (%d)\n", out, obj.Code, obj.Names[0], v, ava)
}
out = fmt.Sprintf("%s Missing :\n", out)
for k, v := range missingItems {
if v > 0 {
obj, _ := getObjItem(getObjItemID(k, ``))
out = fmt.Sprintf("%s [%s] %s : %d\n", out, obj.Code, obj.Names[0], v)
}
}
out = fmt.Sprintf("%s To craft :\n", out)
for k, v := range craftItems {
if v > 0 {
obj, _ := getObjItem(getObjItemID(k, ``))
out = fmt.Sprintf("%s [%s] %s : %d\n", out, obj.Code, obj.Names[0], v)
}
}
out = fmt.Sprintf("%s</code>", out)
c := TGCommand{
Type: commandReplyMsg,
Text: out,
FromMsgID64: p.MsgID64,
FromChatID64: p.ChatID64,
ParseMode: cmdParseModeHTML,
}
TGCmdQueue <- c
err = setJobDone(j.ID64)
logOnError(err, "jobCraftItem : setJobDone")
return
}
func jobGetVault(j Job) {
var (
p JobPayloadGetVault

View File

@ -619,6 +619,8 @@ func JobWorker(id int, jobs <-chan Job) {
jobGetVault(j)
case cacheObjSubType[`job_craft_item`]:
jobCraftItem(j)
case cacheObjSubType[`job_craft_all`]:
jobCraftAll(j)
default:
log.Printf("jobWorker["+strconv.Itoa(id)+"] : No handler for job type #%d.\n", j.JobTypeID64)
}