|
楼主 |
发表于 2024-3-11 16:47:59
|
显示全部楼层
代码最好的注释,是不需要注释。
既然我们这个项目解决的时可维护性的问题,那么就让我们重视这个问题吧
首先,算然我们的机器的地层时状态,但实际写机器的时候,我们不太可能在一个一个状态里搏斗。将常用状态分装为指令是一个很常见的操作。
一个指令有一个文本id和参数
- App.NewCommand("to", App.Options.NewWalk("yz-jindian")),
复制代码
然后可以将指令串成队列
- App.Commands([
- App.NewCommand("to", App.Options.NewWalk("yz-jindian")),
- App.NewCommand("do", "sell " + App.Core.Asset.Asset.UNID),
- App.NewCommand("do", "i2"),
- App.NewCommand("nobusy"),
- App.NewCommand("function", function () {
- App.Core.Asset.Execute()
- }),
- ]).Push()
- App.Next()
复制代码
再配合上必要的逻辑判断
- App.Quest.Zhuliu.Diebao.FinishNext=function(){
- if (App.Data.Ask.Replies[0]=="余玠(Yu jie)告诉你:这篇情报我颇有不解,你帮忙看看?"){
- App.Commands([
- App.NewCommand("delay",2),
- App.NewCommand("function", function () { App.API.Captcha({type:"2words",timeout:15*60*1000}) }),
- App.NewCommand("function", App.Quest.Zhuliu.Diebao.WaitCaptcha),
- ]).Push()
- App.Next()
- return
- }
- App.Next()
- }
复制代码
这就是很直接的将代码流程图化了。
这样做的优点就是,有了流程图,直接就可以啪啦啪啦把代码堆出来。对于类似的任务,可以直接ctrl+C 然后ctrl +V,改一下流程关键部分和触发,就能直接开始跑任务测试了。
范例:破阵任务部分脱敏代码
- App.Quest.Zhuliu.Pozhen.Start = function () {
- App.Quest.Zhuliu.Pozhen.Data = {}
- App.Commands([
- App.NewCommand('prepare', App.PrapareFull),
- App.NewCommand("to", App.Options.NewWalk("gyz")),
- App.NewCommand("planevent",App.Options.NewPlanEvent("#zhuliu",["pozhen"])),
- App.NewCommand("ask", App.Quest.Zhuliu.Pozhen.QuestionJob),
- App.NewCommand("nobusy"),
- App.NewCommand("function", App.Quest.Zhuliu.Pozhen.Next),
- ]).Push()
- App.Next()
- }
- App.Quest.Zhuliu.Pozhen.Go = function (zone, room) {
- App.Quest.Zhuliu.Pozhen.Data.CurrentExit = 0
- App.Quest.Zhuliu.Pozhen.Data.Exits = []
- App.Quest.Zhuliu.Pozhen.Data.Zone = zone
- App.Quest.Zhuliu.Pozhen.Data.Room = room
- App.Quest.Zhuliu.Pozhen.Data.Visited = {}
- let path = App.API.GetZoneRoomPatrol(zone, room)
- if (path == null) {
- Note("无地区[" + zone + "]的信息")
- return
- }
- if (path == "") {
- Note("区域[" + zone + "]不可用")
- App.Quest.Zhuliu.Pozhen.Fail()
- return
- }
- App.Core.Traversal.New()
- App.Data.Traversal.Target = "*"
- App.Data.Traversal.Type = "custom"
- App.Data.Traversal.Answer = path
- App.Data.Traversal.State = "mod.zhuliu.pozhen.arrive"
- App.Commands([
- App.NewCommand("combatinit"),
- App.NewCommand("do", "set wimpy 0"),
- App.NewCommand("powerup"),
- App.NewCommand("function", App.Core.Traversal.Start),
- App.NewCommand("function", App.Quest.Zhuliu.Pozhen.Finish),
- ]).Push()
- App.Next()
- }
- App.Quest.Zhuliu.Pozhen.Finish = function () {
- let cmds = []
- if (App.Data.Room.Name == "阵眼"||App.Data.Room.Name == "阵眼[破阵任务副本]") {
- cmds.push(App.NewCommand("move", App.Options.NewPath("w")))
- }
- cmds = cmds.concat([
- App.NewCommand("nobusy"),
- App.NewCommand("do",GetVariable("connect_cmd")),
- App.NewCommand('prepare', App.PrapareFull),
- App.NewCommand("to", App.Options.NewWalk("gyz")),
- App.NewCommand("ask", App.Quest.Zhuliu.Pozhen.QuestionFinish),
- App.NewCommand("nobusy"),
- App.NewCommand("ask", App.Quest.Zhuliu.Pozhen.QuestionFail),
- App.NewCommand("nobusy"),
- App.NewCommand("do", "jq"),
- App.NewCommand("nobusy"),
- App.NewCommand('prepare', App.PrapareFull),
- ])
- App.Commands(cmds).Push()
- App.Next()
- }
复制代码
|
|