test summary
This commit is contained in:
parent
36d1599817
commit
2ee52e849d
83
job.go
83
job.go
@ -2381,6 +2381,8 @@ func jobCheckVaultLimit(j Job) {
|
||||
var (
|
||||
p JobPayloadCheckVaultLimit
|
||||
p2 JobPayloadGetVault
|
||||
pPost JobPayloadGetVault
|
||||
pPre JobPayloadGetVault
|
||||
b []byte
|
||||
out string
|
||||
)
|
||||
@ -2391,7 +2393,30 @@ func jobCheckVaultLimit(j Job) {
|
||||
err = json.Unmarshal(j.Payload, &p)
|
||||
logOnError(err, "jobCheckVaultLimit : Unmarshal payload")
|
||||
|
||||
if p.Status == 0 {
|
||||
if p.Status == 0 { // check pre war
|
||||
p2.JobCallbackID64 = j.ID64
|
||||
p2.ItemTypeList = make([]int64, 1)
|
||||
p2.ItemTypeList = append(p2.ItemTypeList, cacheObjSubType[`item_res`])
|
||||
|
||||
b, err = json.Marshal(p2)
|
||||
logOnError(err, "jobCheckVaultLimit : Marshal(p2)")
|
||||
|
||||
jobID64, err := createJob(cacheObjSubType[`job_get_vault`], objJobPriority, j.UserID64, 0, time.Now().UTC(), b)
|
||||
|
||||
p.Status = 1
|
||||
p.VaulPreJobID64 = jobID64
|
||||
|
||||
b, err = json.Marshal(p)
|
||||
logOnError(err, "jobCheckVaultLimit : Marshal(p)")
|
||||
|
||||
err = setJobPayloadJSON(j.ID64, p)
|
||||
logOnError(err, "jobCheckVaultLimit : setJobPayloadJSON(p)")
|
||||
|
||||
rescheduleJob(j.ID64, 0, time.Unix(maxUnixTimestamp, 0).UTC())
|
||||
return
|
||||
}
|
||||
|
||||
if p.Status == 1 {
|
||||
p2.JobCallbackID64 = j.ID64
|
||||
p2.ItemTypeList = make([]int64, 0)
|
||||
|
||||
@ -2405,10 +2430,10 @@ func jobCheckVaultLimit(j Job) {
|
||||
b, err = json.Marshal(p2)
|
||||
logOnError(err, "jobCheckVaultLimit : Marshal(p2)")
|
||||
|
||||
jobID64, err := createJob(cacheObjSubType[`job_get_vault`], objJobPriority, j.UserID64, 0, time.Now().UTC(), b)
|
||||
jobID64, err := createJob(cacheObjSubType[`job_get_vault`], objJobPriority, j.UserID64, 0, time.Now().Add(time.Duration(15)*time.Minute).UTC(), b) // schedule for after battle
|
||||
|
||||
p.Status = 1
|
||||
p.VaultJobID64 = jobID64
|
||||
p.Status = 2
|
||||
p.VaultPostJobID64 = jobID64
|
||||
|
||||
b, err = json.Marshal(p)
|
||||
logOnError(err, "jobCheckVaultLimit : Marshal(p)")
|
||||
@ -2420,8 +2445,12 @@ func jobCheckVaultLimit(j Job) {
|
||||
return
|
||||
}
|
||||
|
||||
b = getJobPayload(p.VaultJobID64)
|
||||
err = json.Unmarshal(b, &p2)
|
||||
b = getJobPayload(p.VaultPostJobID64)
|
||||
err = json.Unmarshal(b, &pPost)
|
||||
logOnError(err, "jobCheckVaultLimit : Unmarshal(p2)")
|
||||
|
||||
b = getJobPayload(p.VaultPreJobID64)
|
||||
err = json.Unmarshal(b, &pPre)
|
||||
logOnError(err, "jobCheckVaultLimit : Unmarshal(p2)")
|
||||
|
||||
var empty bool = true
|
||||
@ -2430,7 +2459,7 @@ func jobCheckVaultLimit(j Job) {
|
||||
id := getObjItemID(l.Item, ``)
|
||||
obj, err := getObjItem(id)
|
||||
if err == nil {
|
||||
for _, i := range p2.Vault {
|
||||
for _, i := range pPost.Vault {
|
||||
if id == i.ItemID64 {
|
||||
if i.Quantity > l.Max {
|
||||
empty = false
|
||||
@ -2444,7 +2473,45 @@ func jobCheckVaultLimit(j Job) {
|
||||
}
|
||||
}
|
||||
if empty {
|
||||
out = fmt.Sprintf("%s- all good !", out)
|
||||
out = fmt.Sprintf("%s- all good !\n", out)
|
||||
}
|
||||
|
||||
empty = true
|
||||
out = fmt.Sprintf("%sWar summary :\n", out)
|
||||
for _, iPre := range pPre.Vault {
|
||||
var itemEmpty bool = true
|
||||
for _, iPost := range pPost.Vault {
|
||||
if iPre.ItemID64 == iPost.ItemID64 {
|
||||
itemEmpty = false
|
||||
if iPre.Quantity != iPost.Quantity {
|
||||
empty = false
|
||||
obj, _ := getObjItem(iPre.ItemID64)
|
||||
if iPre.Quantity > iPost.Quantity {
|
||||
out = fmt.Sprintf("%s- [%s] lost %d\n", out, obj.Names[0], iPre.Quantity-iPost.Quantity)
|
||||
} else {
|
||||
out = fmt.Sprintf("%s- [%s] won %d\n", out, obj.Names[0], iPost.Quantity-iPre.Quantity)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if itemEmpty {
|
||||
empty = false
|
||||
obj, _ := getObjItem(iPre.ItemID64)
|
||||
out = fmt.Sprintf("%s- [%s] lost %d\n", out, obj.Names[0], iPre.Quantity)
|
||||
}
|
||||
}
|
||||
for _, iPost := range pPost.Vault {
|
||||
var itemEmpty bool = true
|
||||
for _, iPre := range pPre.Vault {
|
||||
if iPre.ItemID64 == iPost.ItemID64 {
|
||||
itemEmpty = false
|
||||
}
|
||||
}
|
||||
if itemEmpty {
|
||||
empty = false
|
||||
obj, _ := getObjItem(iPre.ItemID64)
|
||||
out = fmt.Sprintf("%s- [%s] won %d\n", out, obj.Names[0], iPost.Quantity)
|
||||
}
|
||||
}
|
||||
|
||||
c := TGCommand{
|
||||
|
Loading…
Reference in New Issue
Block a user