update g deposit

This commit is contained in:
shoopea 2019-08-30 10:14:30 +08:00
parent 10c342f472
commit 574834b2b9
6 changed files with 65 additions and 35 deletions

49
bot.go
View File

@ -639,31 +639,32 @@ func botGDepositAll(m *tb.Message) {
} }
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`01`, `Thread`)) p.ResObjID64 = append(p.ResObjID64, getObjItemID(`01`, `Thread`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`02`, `Stick`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`03`, `Pelt`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`04`, `Bone`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`07`, `Powder`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`08`, `Iron Ore`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`09`, `Cloth`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`10`, `Silver Ore`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`11`, `Bauxite`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`13`, `Magic Stone`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`14`, `Wooden Shaft`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`15`, `Sapphire`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`17`, `Ruby`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`18`, `Hardener`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`19`, `Steel`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`21`, `Bone Powder`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`22`, `String`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`23`, `Coke`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`24`, `Purified Powder`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`31`, `Rope`))
/* /*
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`39`, `Stinky Sumac`)) p.ResObjID64 = append(p.ResObjID64, getObjItemID(`02`, `Stick`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`s01`, `📕Scroll of Rage`)) p.ResObjID64 = append(p.ResObjID64, getObjItemID(`03`, `Pelt`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`r01`, `Champion Sword recipe`)) p.ResObjID64 = append(p.ResObjID64, getObjItemID(`04`, `Bone`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`k01`, `Champion blade`)) p.ResObjID64 = append(p.ResObjID64, getObjItemID(`07`, `Powder`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`w07`, `Rapier`)) p.ResObjID64 = append(p.ResObjID64, getObjItemID(`08`, `Iron Ore`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`09`, `Cloth`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`10`, `Silver Ore`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`11`, `Bauxite`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`13`, `Magic Stone`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`14`, `Wooden Shaft`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`15`, `Sapphire`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`17`, `Ruby`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`18`, `Hardener`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`19`, `Steel`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`21`, `Bone Powder`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`22`, `String`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`23`, `Coke`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`24`, `Purified Powder`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`31`, `Rope`))
/*
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`39`, `Stinky Sumac`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`s01`, `📕Scroll of Rage`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`r01`, `Champion Sword recipe`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`k01`, `Champion blade`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`w07`, `Rapier`))
*/ */
b, _ := json.Marshal(p) b, _ := json.Marshal(p)

5
def.go
View File

@ -274,11 +274,6 @@ type JobPayloadGDeposit struct {
Status int `json:"status"` Status int `json:"status"`
} }
type JobPayloadGDepositForward struct {
ItemID64 int64 `json:"item_id"`
Quantity int64 `json:"quantity"`
}
type JobPayloadSaveRes struct { type JobPayloadSaveRes struct {
MsgID64 int64 `json:"msg_id"` MsgID64 int64 `json:"msg_id"`
ChatID64 int64 `json:"chat_id"` ChatID64 int64 `json:"chat_id"`

11
job.go
View File

@ -737,18 +737,20 @@ func jobGDepositForward(j Job) {
logOnError(err, "jobGDepositForward : getObjMsg") logOnError(err, "jobGDepositForward : getObjMsg")
rule, err := getMsgParsingRule(msg) rule, err := getMsgParsingRule(msg)
logOnError(err, "jobGDepositForward : getMsgParsingRule") logOnError(err, "jobGDepositForward : getMsgParsingRule")
cwm, err := parseSubTypeMessageGDepositAck(msg, rule.re) cwm, err := parseSubTypeMessageGDepositReq(msg, rule.re)
if cwm.ItemID64 == p.ItemID64 && cwm.Quantity == p.Quantity { if cwm.ItemID64 == p.ItemID64 && cwm.Quantity == p.Quantity {
//log.Printf("jobGDepositForward : match (%d / %d).\n", cwm.ItemID64, cwm.Quantity) //log.Printf("jobGDepositForward : match (%d / %d).\n", cwm.ItemID64, cwm.Quantity)
clientFwdCWMsg(j.UserID64, cwm.Msg.ID64, cwm.Msg.ChatID64, cfg.Bot.Depositchat) gDepositForwardMux.Lock()
gDepositForwardMsg = append(gDepositForwardMsg, j.Trigger)
gDepositForwardMux.Unlock()
err = setJobDone(j.ID64) err = setJobDone(j.ID64)
logOnError(err, "jobGDeposit : setJobDone") logOnError(err, "jobGDeposit : setJobDone")
} else { } else {
//log.Printf("jobGDepositForward : found (%d / %d), expected (%d / %d).\n", cwm.ItemID64, cwm.Quantity, p.ItemID64, p.Quantity) //log.Printf("jobGDepositForward : found (%d / %d), expected (%d / %d).\n", cwm.ItemID64, cwm.Quantity, p.ItemID64, p.Quantity)
err = rescheduleJob(j.ID64, 0, time.Unix(maxUnixTimestamp, 0).UTC()) err = rescheduleJob(j.ID64, 0, time.Unix(maxUnixTimestamp, 0).UTC())
logOnError(err, "jobGDepositForward : rescheduleJob") logOnError(err, "jobGDepositForward : rescheduleJob")
setJobCallback(j.ID64, j.UserID64, objSubTypeMessageGDepositAck) setJobCallback(j.ID64, j.UserID64, objSubTypeMessageGDepositReq)
} }
return return
@ -850,13 +852,14 @@ func jobGDeposit(j Job) {
if cwm.Stock[stockIdx].ItemID64 == p.ResObjID64[resIdx] { if cwm.Stock[stockIdx].ItemID64 == p.ResObjID64[resIdx] {
//log.Printf("jobGDeposit : objSubTypeMessageStockAck : Matching ItemID %d (%d).\n", p.ResObjID64[resIdx], cwm.Stock[stockIdx].Quantity) //log.Printf("jobGDeposit : objSubTypeMessageStockAck : Matching ItemID %d (%d).\n", p.ResObjID64[resIdx], cwm.Stock[stockIdx].Quantity)
item, _ := getObjItem(p.ResObjID64[resIdx]) item, _ := getObjItem(p.ResObjID64[resIdx])
cwm.Stock[stockIdx].Quantity = 1 // FIXME REMOVE ONCE DEBUG IS OK
clientSendCWMsg(p.ChatID64, fmt.Sprintf("/g_deposit %s %d", item.Code, cwm.Stock[stockIdx].Quantity)) clientSendCWMsg(p.ChatID64, fmt.Sprintf("/g_deposit %s %d", item.Code, cwm.Stock[stockIdx].Quantity))
p2 := JobPayloadGDepositForward{ p2 := JobPayloadGDepositForward{
ItemID64: p.ResObjID64[resIdx], ItemID64: p.ResObjID64[resIdx],
Quantity: cwm.Stock[stockIdx].Quantity, Quantity: cwm.Stock[stockIdx].Quantity,
} }
b2, _ := json.Marshal(p2) b2, _ := json.Marshal(p2)
err = createJobCallback(objSubTypeJobGDepositForward, j.UserID64, objSubTypeMessageGDepositAck, b2, time.Duration(1*time.Minute)) err = createJobCallback(objSubTypeJobGDepositForward, j.UserID64, objSubTypeMessageGDepositReq, b2, time.Duration(1*time.Minute))
} }
} }
} }

View File

@ -68,6 +68,9 @@ var (
callbacks map[int64]map[int64][]int64 callbacks map[int64]map[int64][]int64
muxCallbacks sync.Mutex muxCallbacks sync.Mutex
gDepositForwardMux sync.Mutex
gDepositForwardMsg []int64
) )
func PrintText(m *tb.Message) { func PrintText(m *tb.Message) {

30
msg.go
View File

@ -23,12 +23,42 @@ func getMsgParsingRule(m *ChatWarsMessage) (*MessageParsingRule, error) {
} }
} }
func parseSubTypeMessageGDepositReq(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageGDepositReq, error) {
cwm := ChatWarsMessageGDepositReq{}
cwm.ItemID64 = getObjItemID(r.ReplaceAllString(m.Text, "${Item}"), ``) // FIXME, handle uXXX items ?
cwm.Quantity, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${Quantity}"), 10, 64)
cwm.Msg = m
return &cwm, nil
}
func parseSubTypeMessageGDepositAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageGDepositAck, error) { func parseSubTypeMessageGDepositAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageGDepositAck, error) {
cwm := ChatWarsMessageGDepositAck{} cwm := ChatWarsMessageGDepositAck{}
cwm.ItemID64 = getObjItemID(``, r.ReplaceAllString(m.Text, "${Item}")) cwm.ItemID64 = getObjItemID(``, r.ReplaceAllString(m.Text, "${Item}"))
cwm.Quantity, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${Quantity}"), 10, 64) cwm.Quantity, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${Quantity}"), 10, 64)
gDepositForwardMux.Lock()
for i := range gDepositForwardMsg {
msg, err := getObjMsg(gDepositForwardMsg[i])
logOnError(err, "parseSubTypeMessageGDepositAck : gDepositForwardMsg")
if err == nil && m.TGUserID64 == msg.TGUserID64 {
rule, err := getMsgParsingRule(msg)
logOnError(err, "parseSubTypeMessageGDepositAck : getMsgParsingRule")
cwmreq, err := parseSubTypeMessageGDepositReq(msg, rule.re)
logOnError(err, "parseSubTypeMessageGDepositAck : parseSubTypeMessageGDepositReq")
if err == nil && cwmreq.ItemID64 == cwm.ItemID64 && cwmreq.Quantity == cwm.Quantity {
clientFwdCWMsg(msg.TGUserID64, m.ID64, m.ChatID64, cfg.Bot.Depositchat)
gDepositForwardMsg[i] = gDepositForwardMsg[len(gDepositForwardMsg)-1]
gDepositForwardMsg = gDepositForwardMsg[:len(gDepositForwardMsg)-1]
break
}
}
}
gDepositForwardMux.Unlock()
cwm.Msg = m cwm.Msg = m
return &cwm, nil return &cwm, nil
} }

View File

@ -531,8 +531,6 @@ func JobWorker(id int, jobs <-chan Job) {
jobGStock(j) jobGStock(j)
case objSubTypeJobGDeposit: case objSubTypeJobGDeposit:
jobGDeposit(j) jobGDeposit(j)
case objSubTypeJobGDepositForward:
jobGDepositForward(j)
default: default:
log.Printf("jobWorker["+strconv.Itoa(id)+"] : No handler for job type #%d.\n", j.JobTypeID) log.Printf("jobWorker["+strconv.Itoa(id)+"] : No handler for job type #%d.\n", j.JobTypeID)
} }