|
本帖最后由 j4b 于 2024-6-23 21:16 编辑
- var dantext =[ {p:"萌新",fens: 0},
- {p:"青铜",fens: 20},
- { p:"白银",fens: 35},
- { p: "黄金",fens: 50},
- { p: "铂金",fens: 100},
- { p:"钻石",fens:150},
- {p: "传奇",fens: 200}
- ];
- if (e.msg=="/段位" ) {
- let found = false;
- for (let i = 0; i < arr.length; i++) {
- if (arr[i].name === e.name) {
- let minDifference = Number.MAX_VALUE;
- let closestP = "";
- for (let j = 0; j < dantext.length; j++) {
- let difference = Math.abs(arr[i].fen - dantext[j].fens);
- if (difference < minDifference) {
- minDifference = difference;
- closestP = dantext[j].p;
- }
- }
- if (closestP !== "") {
- M.instance.sendMessage("msg", {
- msg: `${arr[i].name} 的段位是 ${closestP}`
- });
- found = true;
- }
- }
- }
- if (!found) {
- M.instance.sendMessage("msg", {
- msg: `未找到与 ${e.name} 匹配的记录`
- });
- }
- }
复制代码 感谢猫猫对决机
|
|