|
楼主 |
发表于 2021-11-19 14:20:25
|
显示全部楼层
接下来我们就要改第一个正式的模块,也可以说是一个通用的功能模块
这个模块可以执行一串字符串,比如我们要实现自动配药
那么输入
- #prepare||#to yzyp||ask ping yizhi about 工作||n||peiyao||#afterbusy||#delay 5000||s||give cheng yao to ping yizhi||#loop
复制代码
可以实现
- 准备(取现,买吃喝)
- 前往扬州药铺
- 向平一指打听工作
- 前往配药房
- 配药
- 等待不忙
- 延迟5秒
- 回平一指处
- 给配好的药
- 循环
这样一个循环队列。很明显,诸如打坐,吐纳,练武功,钓鱼之类都能很容易的使用这形势执行
我们先调整queue.task,分割字符串,并进入queue的主状态 core.state.queue.next
- (function (app) {
- let Task = Include("core/task/task.js")
- let queue = Include("core/queue/queue.js")
- var re = /\|\|/
- let Queue = function () {
- Task.call(this, "queue")
- this.Execute = function (data, onFinish, onFail) {
- Task.prototype.Execute.call(this, data, onFinish, onFail)
- if (!data) {
- data = ""
- }
- let list = data.split(re)
- let q=new queue(list)
- app.Send("l")
- app.Automaton.Push("",["core.state.queue.next"]).WithData("Queue",q)
- app.ResponseReady()
- }
- }
- Queue.prototype = Object.create(Task.prototype)
- app.RegisterState(new (Include("core/state/queue/queuenext.js"))())
- app.RegisterState(new (Include("core/state/queue/queueloop.js"))())
- app.RegisterTask(new Queue())
- })(App)
复制代码
https://github.com/hellclient-sc ... /core/task/queue.js
core.state.queue.next主状态代码如下
- (function (app) {
- let basicstate = Include("core/state/basicstate.js")
- let StateQueueNext=function(){
- basicstate.call(this)
- this.ID="core.state.queue.next"
- }
- StateQueueNext.prototype = Object.create(basicstate.prototype)
- StateQueueNext.prototype.Enter=function(context,oldstatue){
- basicstate.prototype.Enter.call(this,context,oldstatue)
- let queue=app.GetContext("Queue")
- if (queue.Remain.length === 0) {
- app.Finish()
- return
- }
- let str = queue.Remain.shift()
- let current = new Directive(str)
- switch (current.Command) {
- case "#prepare":
- app.StartFullPrepare(this.ID)
- break
- case "#to":
- let c = new Directive(current.Data)
- let vehicle
- let target
- if (c.Data) {
- vehicle = c.Command
- target = c.Data
- } else {
- vehicle = ""
- target = c.Command
- }
- app.Drive(vehicle)
- app.NewActive(target,"","core.state.queue.next",false).Start()
- break
- case "#move":
- break
- case "#afterbusy":
- app.Automaton.Push("core.state.queue.next",["nobusy"])
- app.ChangeState("ready")
- break
- case "#do":
- app.NewActive("",current.Data,"core.state.queue.next",false).Start()
- break
- case "#delay":
- let data=current.Data
- if (isNaN(data) || (data - 0) <= 0) {
- throw "delay 的秒数必须为正数"
- }
- let delay=(data - 0) / 1000
- app.Wait(delay,"core.state.queue.next")
- break
- case "#loop":
- if (!app.Stopped) {
- queue.Remain = CloneArray(queue.Queue)
- }
- app.ChangeState("core.state.queue.loop")
- break
- default:
- app.NewActive("",str,"core.state.queue.next",false).Start()
- }
- }
- return StateQueueNext
- })(App)
复制代码 https://github.com/hellclient-scripts/pkuxkx.noob/blob/3b0aac646ea0fafa68348ecbbec06cc53cb41b9e/script/core/state/queue/queuenext.js
很明显,弹出队列里的最新命令,判断并进入相应的状态。本身简单清晰容易维护
对比状态化之前的代码,明显容易维护很多
老代码:https://github.com/hellclient-sc ... /core/task/queue.js
最后是一个core.state.queue.loop状态。这其实是一个空在状态,用途是进入会回到老状态,触发原状态的enter和leave事件
- (function (app) {
- let basicstate = Include("core/state/basicstate.js")
- let StateQueueLoop=function(){
- basicstate.call(this)
- this.ID="core.state.queue.loop"
- }
- StateQueueLoop.prototype = Object.create(basicstate.prototype)
- StateQueueLoop.prototype.Enter=function(context,oldstatue){
- basicstate.prototype.Enter.call(this,context,oldstatue)
- app.ChangeState("core.state.queue.next")
- }
- return StateQueueLoop
- })(App)
复制代码 https://github.com/hellclient-scripts/pkuxkx.noob/blob/3b0aac646ea0fafa68348ecbbec06cc53cb41b9e/script/core/state/queue/queueloop.js
这个模块就做完了。
我们还可以用来进行抄经工作,分为两块
- #prepare||#to qf-sms||#do ask sengren about job
复制代码 将验证码地址复制进新页面打开,并刷新到人能认出的程度
- #to ts-sjy||#do write jing||#afterbusy||#delay 2000||#to qf-sms||#do ask sengren about done
复制代码 将页面里的验证码输入
然后循环。
|
|