pre cw with probe and a bunch script to read game behavior
This commit is contained in:
1 parent
5120219ae2
commit
da8a32f60d
310 files changed
+219693
-872
No files matched your search
@@ -0,0 +1,84 @@
|
||||
package sdkserver
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gac-hkrpg-go/internal/common"
|
||||
pb "gac-hkrpg-go/protocol/proto"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func apiCurrencyWarsCommand(w http.ResponseWriter, command string) {
|
||||
fail := func(err error) { writeJSON(w, map[string]any{"success": false, "output": err.Error()}) }
|
||||
parts := strings.Fields(command)
|
||||
usage := "Usage: /cw status | /cw gold <total> | /cw hp <total>. Changes apply in CW Preparation; adventure inventory is unchanged."
|
||||
if len(parts) < 2 {
|
||||
fail(fmt.Errorf("%s", usage))
|
||||
return
|
||||
}
|
||||
catalog, err := common.LoadCurrencyWarsCatalog()
|
||||
if err != nil {
|
||||
fail(err)
|
||||
return
|
||||
}
|
||||
cfg, err := common.LoadRuntimeConfig()
|
||||
if err != nil {
|
||||
fail(err)
|
||||
return
|
||||
}
|
||||
snapshot, err := common.ReadCurrencyWarsSnapshot(cfg.PlayerUID, catalog.ClientVersion, catalog.Provenance.GameAssemblySHA256)
|
||||
if err != nil {
|
||||
fail(err)
|
||||
return
|
||||
}
|
||||
if snapshot == nil {
|
||||
fail(fmt.Errorf("no saved CW run"))
|
||||
return
|
||||
}
|
||||
var data pb.GridFightGetDataScRsp
|
||||
if err = proto.Unmarshal(snapshot.WireData, &data); err != nil {
|
||||
fail(err)
|
||||
return
|
||||
}
|
||||
run := data.DHFOFLFCLAH
|
||||
if run == nil {
|
||||
fail(fmt.Errorf("no active CW run"))
|
||||
return
|
||||
}
|
||||
var player *pb.NIHNGPKHEPC
|
||||
for _, c := range run.NAGDJGMMCBE {
|
||||
if v := c.GetFAOCFBOFCJP(); v != nil {
|
||||
player = v
|
||||
}
|
||||
}
|
||||
if player == nil {
|
||||
fail(fmt.Errorf("CW player state missing"))
|
||||
return
|
||||
}
|
||||
field := strings.ToLower(parts[1])
|
||||
if field == "status" && len(parts) == 2 {
|
||||
writeJSON(w, map[string]any{"success": true, "output": fmt.Sprintf("CW run=%d revision=%d gold=%d hp=%d/%d level=%d", run.UniqueId, snapshot.Revision, player.Gold, player.GridFightLineupHp, player.PPKKHHNEOHB, player.EHNJDIDABHD)})
|
||||
return
|
||||
}
|
||||
if len(parts) != 3 || (field != "gold" && field != "hp") {
|
||||
fail(fmt.Errorf("%s", usage))
|
||||
return
|
||||
}
|
||||
value, err := strconv.ParseUint(parts[2], 10, 32)
|
||||
if err != nil {
|
||||
fail(fmt.Errorf("value must be a nonnegative uint32"))
|
||||
return
|
||||
}
|
||||
if field == "hp" && (value == 0 || value > uint64(player.PPKKHHNEOHB)) {
|
||||
fail(fmt.Errorf("HP must be 1..%d", player.PPKKHHNEOHB))
|
||||
return
|
||||
}
|
||||
id, err := common.QueueCurrencyWarsCommand(cfg.PlayerUID, run.UniqueId, field, uint32(value))
|
||||
if err != nil {
|
||||
fail(err)
|
||||
return
|
||||
}
|
||||
writeJSON(w, map[string]any{"success": true, "state": "queued", "request_id": id, "output": fmt.Sprintf("Queued CW %s=%d for run %d. Applies at the next heartbeat in Preparation.", field, value, run.UniqueId)})
|
||||
}
|
||||
Reference in new issue
Block a user