|
发表于 2024-9-6 14:37:44
|
显示全部楼层
本帖最后由 jarlyyn 于 2024-9-6 02:41 PM 编辑
具体的实现是用变体漏桶算法的
参考
https://www.pkuxkx.com/forum/thread-49204-1-1.html
实际代码
- })
- App.Core.Overheat.Commands = {
- "west": 13,
- "w": 13,
- "north": 13,
- "n": 13,
- "east": 13,
- "e": 13,
- "south": 13,
- "s": 13,
- "up": 13,
- "u": 13,
- "down": 13,
- "d": 13,
- "enter": 13,
- "out": 13,
- "xiaojing": 13,
- "biandao": 13,
- "northeast": 13,
- "ne": 13,
- "southeast": 13,
- "se": 13,
- "southwest": 13,
- "sw": 13,
- "northwest": 13,
- "nw": 13,
- "northup": 13,
- "nu": 13,
- "eastup": 13,
- "eu": 13,
- "southup": 13,
- "su": 13,
- "westup": 13,
- "wu": 13,
- "northdown": 13,
- "nd": 13,
- "eastdown": 13,
- "ed": 13,
- "southdown": 13,
- "sd": 13,
- "westdown": 13,
- "eu": 13,
- "i": 15,
- "i2": 8,
- "l": 20,
- "ask":50,
- "jq":160,
- "wield":5,
- "jifa":10,
- "skills":123,
- }
- App.Core.Overheat.Value = 0
- App.Core.Overheat.Current = 0
- App.Core.Overheat.IsOverThreshold = function () {
- return App.Core.Overheat.Value > App.Core.OverheatMode.Current().Threshold();
- }
- App.Core.Overheat.OnTimer = function () {
- App.Core.Overheat.Last.unshift(App.Core.Overheat.Current)
- if (App.Core.Overheat.Last.length > max) {
- App.Core.Overheat.Last = App.Core.Overheat.Last.slice(0, -1)
- }
- App.Core.Overheat.Last = [...App.Core.Overheat.Last]
- App.Core.Overheat.Value = 0
- if (App.Core.Overheat.Last.length) {
- for (var i = 0; i < App.Core.Overheat.Last.length; i++) {
- App.Core.Overheat.Value += App.Core.Overheat.Last[i]
- }
- App.Core.Overheat.Value=Math.floor(App.Core.Overheat.Value/App.Core.Overheat.Last.length)
- let shortvalue=0
- let shortlist=App.Core.Overheat.Last.slice(-short)
- for (var i = 0; i < shortlist.length; i++) {
- shortvalue += shortlist[i]
- }
- shortvalue=Math.floor(shortvalue/shortlist.length)
- if (shortvalue>App.Core.Overheat.Value){
- App.Core.Overheat.Value=shortvalue
- }
- }
- App.Core.Overheat.Current = 0
- App.Raise("core.overheat.updated", App.Core.Overheat.Value)
- }
- App.RegisterCallback("app.core.overheat.onsend", function (data) {
- if (App.Data.Room.Name&&App.Data.Room.Location){
- return;
- }
- if (data) {
- for (var i = 0; i < data.length; i++) {
- let v = App.Core.Overheat.Commands[data[i]]
- if (v) {
- App.Core.Overheat.Current += v
- }
- }
- }
- })
- App.Bind("Send", "app.core.overheat.onsend")
复制代码
建立高消耗指令清单
记录所有已发送的指令消耗,统计最近的一段时间的消耗,并进行限流。
我这里还建立了个长和短两个限流,避免 突发 和 长期低温过热。
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|