2022-06-14 22:07:24 +00:00
|
|
|
|
import fetch from "node-fetch";
|
|
|
|
|
import lodash from "lodash";
|
|
|
|
|
import Character from "../models/Character.js";
|
|
|
|
|
import moment from "moment";
|
2022-06-20 22:55:08 +00:00
|
|
|
|
import { artiIdx, artiSetMap, attrMap } from "./miao-meta.js";
|
|
|
|
|
import cmeta from "./enka-char.js";
|
2022-06-14 22:07:24 +00:00
|
|
|
|
|
2022-07-02 02:38:12 +00:00
|
|
|
|
const url = "http://49.232.91.210/profile/detail?token=kokomi";
|
2022-06-14 22:07:24 +00:00
|
|
|
|
|
2022-06-14 22:14:58 +00:00
|
|
|
|
let Miao = {
|
|
|
|
|
key: "miao",
|
2022-06-14 22:07:24 +00:00
|
|
|
|
cd: 1,
|
2022-06-27 20:46:49 +00:00
|
|
|
|
async request({ e, uid, avatar = '', config }) {
|
|
|
|
|
let profileApi = config.miaoApi && lodash.isFunction(config.miaoApi) ? config.miaoApi : function ({ uid }) {
|
|
|
|
|
return `http://49.232.91.210/profile/list?uid=${uid}`
|
|
|
|
|
};
|
|
|
|
|
let api = profileApi({ uid, avatar });
|
2022-06-14 22:07:24 +00:00
|
|
|
|
let data;
|
|
|
|
|
let req = await fetch(api);
|
|
|
|
|
data = await req.json();
|
|
|
|
|
if (data.status !== 0) {
|
|
|
|
|
e.reply(data.msg || "请求失败");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!data.uidListData || data.uidListData.length === 0) {
|
2022-06-27 20:46:49 +00:00
|
|
|
|
e.reply(`请打开游戏内角色展柜的“显示详情”后,等待5分钟重新获取面板`);
|
2022-06-14 22:07:24 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-14 22:14:58 +00:00
|
|
|
|
return Miao.getData(uid, data);
|
2022-06-14 22:07:24 +00:00
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
getData(uid, data) {
|
|
|
|
|
let ret = {
|
|
|
|
|
uid,
|
|
|
|
|
chars: {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lodash.forEach({
|
|
|
|
|
name: "nickname",
|
|
|
|
|
//avatar: "profilePicture.avatarId",
|
|
|
|
|
lv: "level"
|
|
|
|
|
}, (src, key) => {
|
|
|
|
|
ret[key] = lodash.get(data, src, "");
|
|
|
|
|
})
|
|
|
|
|
lodash.forEach(data.uidListData, (ds) => {
|
2022-06-14 22:14:58 +00:00
|
|
|
|
let char = Miao.getAvatar(ds);
|
2022-06-14 22:07:24 +00:00
|
|
|
|
ret.chars[char.id] = char;
|
|
|
|
|
})
|
|
|
|
|
return ret;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
getAvatar(ds) {
|
|
|
|
|
let char = Character.get(ds.usernameid);
|
|
|
|
|
let now = moment();
|
|
|
|
|
return {
|
|
|
|
|
id: ds.usernameid,
|
|
|
|
|
name: char ? char.name : "",
|
2022-06-14 22:14:58 +00:00
|
|
|
|
dataSource: "miao-pre",
|
2022-06-14 22:07:24 +00:00
|
|
|
|
updateTime: now.format("YYYY-MM-DD HH:mm:ss"),
|
|
|
|
|
lv: ds.level
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
|
2022-07-02 02:38:12 +00:00
|
|
|
|
async getCharData(uid, ds, saveCharData, { config = {} }) {
|
2022-06-15 21:09:39 +00:00
|
|
|
|
if (ds.dataSource !== "miao-pre" || !ds.id) {
|
2022-06-14 22:07:24 +00:00
|
|
|
|
return ds;
|
|
|
|
|
}
|
|
|
|
|
try {
|
2022-07-02 02:38:12 +00:00
|
|
|
|
let profileApi = function ({ uid, avatar }) {
|
|
|
|
|
return `http://49.232.91.210/profile/detail?uid=${uid}&avatar=${avatar}`
|
|
|
|
|
};
|
|
|
|
|
if (config.miaoApi && lodash.isFunction(config.miaoApi)) {
|
|
|
|
|
profileApi = config.miaoApi;
|
|
|
|
|
}
|
|
|
|
|
let api = profileApi({ uid, avatar: ds.id });
|
2022-06-14 22:07:24 +00:00
|
|
|
|
let req = await fetch(api);
|
|
|
|
|
let data = await req.json();
|
|
|
|
|
if (data.status === 0 && data.uidData) {
|
2022-06-14 22:14:58 +00:00
|
|
|
|
data = Miao.getAvatarDetail(data);
|
2022-06-14 22:07:24 +00:00
|
|
|
|
if (data) {
|
|
|
|
|
saveCharData(uid, data);
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ds;
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.log(err);
|
|
|
|
|
return ds;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
getAvatarDetail(data) {
|
|
|
|
|
let ds = data.uidData;
|
|
|
|
|
let char = Character.get(ds.id);
|
|
|
|
|
let now = moment();
|
|
|
|
|
return {
|
|
|
|
|
id: ds.id,
|
|
|
|
|
name: char ? char.name : "",
|
2022-06-14 22:14:58 +00:00
|
|
|
|
dataSource: "miao",
|
2022-06-14 22:07:24 +00:00
|
|
|
|
updateTime: now.format("YYYY-MM-DD HH:mm:ss"),
|
|
|
|
|
lv: ds.level,
|
|
|
|
|
fetter: ds.fetterLevel,
|
2022-06-14 22:14:58 +00:00
|
|
|
|
attr: Miao.getAttr(data.uidDataCombatValue),
|
|
|
|
|
weapon: Miao.getWeapon(ds.weapon),
|
|
|
|
|
artis: Miao.getArtifact(data.uidDataByReliquary),
|
2022-06-14 22:07:24 +00:00
|
|
|
|
cons: ds.constellationNum,
|
2022-06-14 22:14:58 +00:00
|
|
|
|
talent: Miao.getTalent(char.id, ds.skill),
|
2022-06-14 22:07:24 +00:00
|
|
|
|
_priority: 10
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
getAttr(data) {
|
|
|
|
|
let ret = {};
|
|
|
|
|
lodash.forEach({
|
|
|
|
|
atk: "attack",
|
|
|
|
|
atkBase: "baseATK",
|
|
|
|
|
hp: "health",
|
|
|
|
|
hpBase: "baseHP",
|
|
|
|
|
def: "defense",
|
|
|
|
|
defBase: "baseDEF",
|
|
|
|
|
mastery: "elementMastery",
|
|
|
|
|
cRate: {
|
|
|
|
|
src: "critRate",
|
|
|
|
|
pct: true
|
|
|
|
|
},
|
|
|
|
|
cDmg: {
|
|
|
|
|
src: "critDamage",
|
|
|
|
|
pct: true
|
|
|
|
|
},
|
|
|
|
|
hInc: {
|
|
|
|
|
src: "heal",
|
|
|
|
|
pct: true
|
|
|
|
|
},
|
|
|
|
|
recharge: {
|
|
|
|
|
src: "recharge",
|
|
|
|
|
pct: true
|
|
|
|
|
}
|
|
|
|
|
}, (cfg, key) => {
|
|
|
|
|
if (!lodash.isObject(cfg)) {
|
|
|
|
|
cfg = { src: cfg };
|
|
|
|
|
}
|
|
|
|
|
let val = data[cfg.src] || 0;
|
|
|
|
|
if (cfg.pct) {
|
|
|
|
|
val = val * 100
|
|
|
|
|
}
|
|
|
|
|
ret[key] = val;
|
|
|
|
|
})
|
2022-06-15 21:09:39 +00:00
|
|
|
|
let maxDmg = 0, hurt = data.addHurt || {};
|
2022-06-14 22:07:24 +00:00
|
|
|
|
lodash.forEach("fire,elec,water,grass,wind,rock,ice".split(","), (key) => {
|
2022-06-15 21:09:39 +00:00
|
|
|
|
maxDmg = Math.max(hurt[key] * 100, maxDmg);
|
2022-06-14 22:07:24 +00:00
|
|
|
|
});
|
2022-06-15 21:09:39 +00:00
|
|
|
|
ret.dmgBonus = maxDmg;
|
|
|
|
|
ret.phyBonus = hurt.physical * 100;
|
2022-06-14 22:07:24 +00:00
|
|
|
|
return ret;
|
|
|
|
|
},
|
|
|
|
|
getWeapon(weapon) {
|
|
|
|
|
return {
|
|
|
|
|
name: weapon.name,
|
|
|
|
|
star: weapon.rank,
|
|
|
|
|
level: weapon.level,
|
|
|
|
|
promote: weapon.promoteLevel,
|
|
|
|
|
affix: (weapon.affixLevel || 0) + 1
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
getArtifact(data) {
|
|
|
|
|
let ret = {};
|
|
|
|
|
let get = function (d) {
|
|
|
|
|
if (!d) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
let name = d.name;
|
|
|
|
|
name = name.replace("FIGHT_PROP_", "");
|
|
|
|
|
if (!attrMap[name]) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
let value = d.value;
|
|
|
|
|
if (value && value < 1) {
|
|
|
|
|
value = value * 100;
|
|
|
|
|
}
|
|
|
|
|
return [attrMap[name], value];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lodash.forEach(data, (ds) => {
|
|
|
|
|
let sub = ds.appendAffix || [];
|
|
|
|
|
let idx = artiIdx[ds.type];
|
|
|
|
|
if (!idx) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ret[`arti${idx}`] = {
|
|
|
|
|
name: ds.name,
|
|
|
|
|
set: artiSetMap[ds.name] || "",
|
|
|
|
|
level: ds.level,
|
|
|
|
|
main: get(ds.mainAffix),
|
|
|
|
|
attrs: [
|
|
|
|
|
get(sub[0]),
|
|
|
|
|
get(sub[1]),
|
|
|
|
|
get(sub[2]),
|
|
|
|
|
get(sub[3])
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
return ret;
|
|
|
|
|
},
|
|
|
|
|
getTalent(charid, data = {}) {
|
|
|
|
|
let cm = cmeta[charid] || {};
|
|
|
|
|
let cn = cm.Skills || {};
|
|
|
|
|
let idx = 1;
|
|
|
|
|
let idxMap = { 0: 'a', 1: 'e', 2: 'q', 'a': 'a', 's': 'e', 'e': 'q' };
|
|
|
|
|
lodash.forEach(cn, (n, id) => {
|
|
|
|
|
let nRet = /skill_(\w)/.exec(n.toLowerCase());
|
|
|
|
|
idxMap[id] = nRet && nRet[1] ? idxMap[nRet[1]] : idxMap[idx];
|
|
|
|
|
idx++;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let ret = {};
|
|
|
|
|
lodash.forEach(data, (ds) => {
|
|
|
|
|
let key = idxMap[ds.id];
|
|
|
|
|
ret[key] = {
|
|
|
|
|
level_original: ds.level,
|
|
|
|
|
level_current: ds.level
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
return ret;
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-14 22:14:58 +00:00
|
|
|
|
export default Miao;
|