Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
jarlyyn committed Jan 10, 2022
1 parent bebeb6f commit 4facae4
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 2 deletions.
18 changes: 18 additions & 0 deletions script.toml
Expand Up @@ -1523,6 +1523,24 @@ Channel = "pkuxkx.noob"
Inverse = false
Italic = false
Variable = ""
[[Timers]]
ID = "gc"
Name = "gc"
Enabled = true
Hour = 0
Minute = 0
Second = 0.2
Send = ""
Script = "App.OnTimerGC"
AtTime = false
SendTo = 0
ActionWhenDisconnectd = true
Temporary = false
OneShot = false
Group = ""
Variable = ""
OmitFromLog = false
OmitFromOutput = false
[[Timers]]
ID = "steptimeout"
Name = "steptimeout"
Expand Down
3 changes: 3 additions & 0 deletions script/app.js
Expand Up @@ -11,6 +11,9 @@ App.Init=function(){
}
App.Mods={}
}
App.OnTimerGC=function(name){
App.Raise("gc")
}
App.RegisterCallback=function(name,fn){
App.Callbacks[name]=fn
}
Expand Down
22 changes: 22 additions & 0 deletions script/core/move.js
Expand Up @@ -4,17 +4,39 @@
app.NewMove = function (mode, target,data) {
return new Move(mode,target,data)
}
app.GetMoved=function(){
gc()
return moved.length
}
var moved=[]
var gc=function(){
newmoved=[]
var now=(new Date()).getTime()
moved.forEach(function(ts){
if ((now-ts)<500){
newmoved.push(ts)
}
})
moved=newmoved
}
app.RegisterCallback("core.move.gc", function () {
gc()
})
app.Bind("gc","core.move.gc")
app.RegisterCallback("core.move.onroomobjend", function () {
moved.push((new Date()).getTime())
app.OnStateEvent("move.onRoomObjEnd")
})
app.Bind("OnRoomEnd", "core.move.onroomobjend")
app.OnMoveStepTimeout = function (name) {
app.OnStateEvent("move.stepTimeout")
}
app.Core.OnMoveRetry=function(name, output, wildcards){
moved.splice(-1)
app.OnStateEvent("move.retry")
}
app.Core.OnMoveIgnore=function(name, output, wildcards){
moved.splice(-1)
app.OnStateEvent("move.ignore")
}
app.Core.OnMoveEnterBoat=function(name, output, wildcards){
Expand Down
8 changes: 6 additions & 2 deletions script/core/vehicle.js
Expand Up @@ -2,13 +2,17 @@
let run =Include("core/vehicle/run.js")
let go = Include("core/vehicle/go.js")
let cart = Include("core/vehicle/cart.js")
let slow = Include("core/vehicle/slow.js")

app.Vehicle=null
app.Vehicles={
Run:new run(),
Go:new go(),
Cart:new cart(),
Slow:new slow(),
}
app.Vehicle=app.Vehicles.Run
app.DefaultVehicle=app.Vehicles.Slow
app.Vehicle=app.DefaultVehicle
app.Drive=function(id){
if(id){
for (let key in app.Vehicles) {
Expand All @@ -19,7 +23,7 @@
}
throw "未知的载具 " +id
}else{
app.Vehicle=app.Vehicles.Run
app.Vehicle=app.DefaultVehicle
}
}
app.RegisterCallback("core.vehicle.inittags",function(){
Expand Down
18 changes: 18 additions & 0 deletions script/core/vehicle/slow.js
@@ -0,0 +1,18 @@
(function (app) {
let Vehicle = Include("core/vehicle/vehicle.js")
let Slow = function () {
Vehicle.call(this)
this.ID="slow"
this.MultiStep=false
this.Fly=true
this.Sender=function(cmd){
if (app.GetMoved()<5){
app.Send(cmd)
}else{
app.OnStateEvent("move.retry")
}
}
}
Slow.prototype = Object.create(Vehicle.prototype)
return Slow
})(App)

0 comments on commit 4facae4

Please sign in to comment.