From 302cebabf35b454fe20a281e26ad01376695a9cc Mon Sep 17 00:00:00 2001 From: mengxinzxz <2223529500@qq.com> Date: Mon, 29 Apr 2024 09:34:27 +0800 Subject: [PATCH] =?UTF-8?q?tempname=E8=8E=B7=E5=8F=96bugfix=EF=BC=8C?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ①修复无get.character的name获取tempname引发的报错问题(eg:国战) ②格式化noname\game\index.js为新Prettier准则 --- noname/game/index.js | 1055 +++++++++++------------------------------- 1 file changed, 279 insertions(+), 776 deletions(-) diff --git a/noname/game/index.js b/noname/game/index.js index a42e73e4b..61b6062b1 100644 --- a/noname/game/index.js +++ b/noname/game/index.js @@ -16,14 +16,7 @@ import { lib } from "../library/index.js"; import { _status } from "../status/index.js"; import { ui } from "../ui/index.js"; import { gnc } from "../gnc/index.js"; -import { - userAgent, - Uninstantable, - GeneratorFunction, - AsyncFunction, - delay, - nonameInitialized, -} from "../util/index.js"; +import { userAgent, Uninstantable, GeneratorFunction, AsyncFunction, delay, nonameInitialized } from "../util/index.js"; import { DynamicStyle } from "./dynamic-style/index.js"; import { GamePromises } from "./promises.js"; @@ -111,10 +104,10 @@ export class Game { if (typeof event.name != "string") return; const handlerMap = this._handlers[event.name]; if (!handlerMap) return; - Object.keys(handlerMap).forEach((key) => { + Object.keys(handlerMap).forEach(key => { const list = handlerMap[key]; if (!list) return; - list.forEach((handler) => { + list.forEach(handler => { event.pushHandler(key, handler); }); }); @@ -123,25 +116,13 @@ export class Game { //Stratagem //谋攻 setStratagemBuffCost(cardName, cost) { - return game.broadcastAll( - (clientCardName, clientCost) => lib.stratagemBuff.cost.set(clientCardName, clientCost), - cardName, - cost - ); + return game.broadcastAll((clientCardName, clientCost) => lib.stratagemBuff.cost.set(clientCardName, clientCost), cardName, cost); } setStratagemBuffEffect(cardName, effect) { - return game.broadcastAll( - (clientCardName, clientEffect) => lib.stratagemBuff.cost.set(clientCardName, clientEffect), - cardName, - effect - ); + return game.broadcastAll((clientCardName, clientEffect) => lib.stratagemBuff.cost.set(clientCardName, clientEffect), cardName, effect); } setStratagemBuffPrompt(cardName, prompt) { - return game.broadcastAll( - (clientCardName, clientPrompt) => lib.stratagemBuff.cost.set(clientCardName, clientPrompt), - cardName, - prompt - ); + return game.broadcastAll((clientCardName, clientPrompt) => lib.stratagemBuff.cost.set(clientCardName, clientPrompt), cardName, prompt); } /** * 添加新的属性杀 @@ -158,7 +139,7 @@ export class Game { hasNature(item, nature, player) { var natures = get.natureList(item, player); if (!nature) return natures.length > 0; - if (nature == "linked") return natures.some((n) => lib.linked.includes(n)); + if (nature == "linked") return natures.some(n => lib.linked.includes(n)); return get.is.sameNature(natures, nature); } /** @@ -267,40 +248,19 @@ export class Game { return yingbianEffect; } setYingbianConditionColor(yingbianCondition, color) { - return game.broadcastAll( - (yingbianCondition, color) => lib.yingbian.condition.color.set(yingbianCondition, color), - yingbianCondition, - color - ); + return game.broadcastAll((yingbianCondition, color) => lib.yingbian.condition.color.set(yingbianCondition, color), yingbianCondition, color); } setComplexYingbianCondition(yingbianCondition, condition) { - return game.broadcastAll( - (yingbianCondition, condition) => - lib.yingbian.condition.complex.set(yingbianCondition, condition), - yingbianCondition, - condition - ); + return game.broadcastAll((yingbianCondition, condition) => lib.yingbian.condition.complex.set(yingbianCondition, condition), yingbianCondition, condition); } setSimpleYingbianCondition(yingbianCondition, condition) { - return game.broadcastAll( - (yingbianCondition, condition) => lib.yingbian.condition.simple.set(yingbianCondition, condition), - yingbianCondition, - condition - ); + return game.broadcastAll((yingbianCondition, condition) => lib.yingbian.condition.simple.set(yingbianCondition, condition), yingbianCondition, condition); } setYingbianEffect(yingbianEffect, effect) { - return game.broadcastAll( - (yingbianEffect, effect) => lib.yingbian.effect.set(yingbianEffect, effect), - yingbianEffect, - effect - ); + return game.broadcastAll((yingbianEffect, effect) => lib.yingbian.effect.set(yingbianEffect, effect), yingbianEffect, effect); } setYingbianPrompt(yingbian, prompt) { - return game.broadcastAll( - (yingbian, prompt) => lib.yingbian.prompt.set(yingbian, prompt), - yingbian, - prompt - ); + return game.broadcastAll((yingbian, prompt) => lib.yingbian.prompt.set(yingbian, prompt), yingbian, prompt); } /** * Dynamic Style Manager @@ -370,8 +330,7 @@ export class Game { node._link.current = this.link; const tmpName = node.lastChild.innerHTML; node.lastChild.innerHTML = config.item[this._link]; - if (config.onclick && config.onclick.call(node, this._link, this) === false) - node.lastChild.innerHTML = tmpName; + if (config.onclick && config.onclick.call(node, this._link, this) === false) node.lastChild.innerHTML = tmpName; if (config.update) config.update(); }, menu.childElementCount - 2 @@ -412,18 +371,16 @@ export class Game { if (background.startsWith("blob:") || background.startsWith("data:")) { uiBackground.setBackgroundImage(background); } else if (background.startsWith("db:")) uiBackground.setBackgroundDB(background.slice(3)); - else if (background.startsWith("ext:")) - uiBackground.setBackgroundImage(`extension/${background.slice(4)}`); + else if (background.startsWith("ext:")) uiBackground.setBackgroundImage(`extension/${background.slice(4)}`); else if (background == "default") { uiBackground.addTempClass("start"); style.backgroundImage = "none"; } else if (background.startsWith("custom_")) { style.backgroundImage = "none"; - game.getDB("image", background).then((fileToLoad) => { + game.getDB("image", background).then(fileToLoad => { if (!fileToLoad) return; const fileReader = new FileReader(); - fileReader.onload = (fileLoadedEvent) => - (style.backgroundImage = `url(${fileLoadedEvent.target.result})`); + fileReader.onload = fileLoadedEvent => (style.backgroundImage = `url(${fileLoadedEvent.target.result})`); fileReader.readAsDataURL(fileToLoad, "UTF-8"); }); } else uiBackground.setBackgroundImage(`image/background/${background}.jpg`); @@ -436,7 +393,7 @@ export class Game { * 用给定的BPM、节拍和偏移生成谱面 */ generateBeatmapTimeleap(bpm, beats, offset) { - return beats.map((value) => Math.round((value * 60000) / bpm + (offset || 0))); + return beats.map(value => Math.round((value * 60000) / bpm + (offset || 0))); } updateRenku() { game.broadcast(function (renku) { @@ -457,7 +414,7 @@ export class Game { cards = [cards]; } // @ts-ignore - cards.forEach((card) => card.addKnower(players)); + cards.forEach(card => card.addKnower(players)); } /** * 移除牌的所有知情者。 @@ -470,7 +427,7 @@ export class Game { cards = [cards]; } // @ts-ignore - cards.forEach((card) => card.clearKnowers()); + cards.forEach(card => card.clearKnowers()); } /** * @param { { [key: string]: any } } [arg] @@ -639,7 +596,7 @@ export class Game { */ hasAllGlobalHistory(key, filter, last) { if (!key || !filter) return false; - return _status.globalHistory.some((value) => { + return _status.globalHistory.some(value => { if (value[key]) { if (last && value[key].includes(last)) { const lastIndex = value[key].indexOf(last); @@ -666,7 +623,7 @@ export class Game { checkAllGlobalHistory(key, filter, last) { if (!key || !filter) return; let stopped = false; - _status.globalHistory.forEach((value) => { + _status.globalHistory.forEach(value => { if (value[key]) { if (last && value[key].includes(last) && !stopped) { stopped = true; @@ -695,7 +652,7 @@ export class Game { */ getAllGlobalHistory(key, filter, last) { const history = []; - _status.globalHistory.forEach((value) => { + _status.globalHistory.forEach(value => { if (!key || !value[key]) { history.push(value); } else { @@ -935,11 +892,8 @@ export class Game { (node.system = ui.create.system(lib.translate[skill], null, true, true)), () => { const uiIntro = ui.create.dialog("hidden"); - uiIntro.addText(player ? `来源:${get.translation(player)}` : "地图").style.margin = - "0"; - uiIntro._place_text = uiIntro.add( - ui.create.div(".text", lib.translate[`${skill}_info`]) - ); + uiIntro.addText(player ? `来源:${get.translation(player)}` : "地图").style.margin = "0"; + uiIntro._place_text = uiIntro.add(ui.create.div(".text", lib.translate[`${skill}_info`])); uiIntro.add(ui.create.div(".placeholder.slim")); return uiIntro; }, @@ -962,7 +916,7 @@ export class Game { let n = updates.length; for (let i = 0; i < updates.length; i++) { if (lib.node && lib.node.fs) { - lib.node.fs.access(__dirname + "/" + updates[i], (err) => { + lib.node.fs.access(__dirname + "/" + updates[i], err => { if (!err) { let stat = lib.node.fs.statSync(__dirname + "/" + updates[i]); // @ts-ignore @@ -1244,14 +1198,7 @@ export class Game { ui.timer.show(); let num; //这么一大行都是为了祢衡 - if ( - _status.event && - _status.event.name == "chooseToUse" && - _status.event.type == "phase" && - _status.event.player && - _status.event.player.forceCountChoose && - typeof _status.event.player.forceCountChoose.phaseUse == "number" - ) { + if (_status.event && _status.event.name == "chooseToUse" && _status.event.type == "phase" && _status.event.player && _status.event.player.forceCountChoose && typeof _status.event.player.forceCountChoose.phaseUse == "number") { num = _status.event.player.forceCountChoose.phaseUse; } else if (_status.connectMode) { num = lib.configOL.choose_timeout; @@ -1275,11 +1222,7 @@ export class Game { } else if (_status.event.player.forceCountChoose && _status.event.isMine() && !_status.countDown) { let info = _status.event.player.forceCountChoose; let num; - if ( - _status.event.name == "chooseToUse" && - _status.event.type == "phase" && - typeof info.phaseUse == "number" - ) { + if (_status.event.name == "chooseToUse" && _status.event.type == "phase" && typeof info.phaseUse == "number") { num = info.phaseUse; } else if (typeof info[_status.event.name] == "number") { num = info[_status.event.name]; @@ -1299,10 +1242,7 @@ export class Game { } else if (ui.confirm.str.includes("o")) { ui.click.ok(); } - } else if ( - ["chooseControl", "chooseBool"].includes(_status.event.name) && - _status.paused - ) { + } else if (["chooseControl", "chooseBool"].includes(_status.event.name) && _status.paused) { _status.event.result = "ai"; game.resume(); } else { @@ -1364,8 +1304,7 @@ export class Game { delete game.ws; } let str = ""; - if (!ip.startsWith("wss://") && !ip.startsWith("ws://")) - str = get.config("wss_mode", "connect") ? "wss://" : "ws://"; + if (!ip.startsWith("wss://") && !ip.startsWith("ws://")) str = get.config("wss_mode", "connect") ? "wss://" : "ws://"; game.ws = new WebSocket(str + ip + ""); } catch { // 今天狂神龙尊来了这里也没有参数 @@ -1443,8 +1382,7 @@ export class Game { if (_status.video) break; } if (path.startsWith("ext:")) path = path.replace(/^ext:/, "extension/"); - else if (!["db:", "blob:", "data:"].some((prefix) => path.startsWith(prefix))) - path = `audio/${path}`; + else if (!["db:", "blob:", "data:"].some(prefix => path.startsWith(prefix))) path = `audio/${path}`; if (!lib.config.repeat_audio && _status.skillaudio.includes(path)) return; } const audio = document.createElement("audio"); @@ -1457,21 +1395,17 @@ export class Game { setTimeout(() => _status.skillaudio.remove(path), 1000); game.addVideo("playAudio", null, path); }; - audio.onended = (event) => audio.remove(); - audio.onerror = (event) => { + audio.onended = event => audio.remove(); + audio.onerror = event => { audio.remove(); if (onError) onError(event); }; new Promise((resolve, reject) => { - if (path.startsWith("db:")) - game.getDB("image", path.slice(3)).then( - (octetStream) => resolve(get.objectURL(octetStream)), - reject - ); + if (path.startsWith("db:")) game.getDB("image", path.slice(3)).then(octetStream => resolve(get.objectURL(octetStream)), reject); else if (lib.path.extname(path)) resolve(`${lib.assetURL}${path}`); else if (URL.canParse(path)) resolve(path); else resolve(`${lib.assetURL}${path}.mp3`); - }).then((resolvedPath) => { + }).then(resolvedPath => { audio.src = resolvedPath; ui.window.appendChild(audio); }); @@ -1520,31 +1454,30 @@ export class Game { if (typeof player === "string") player = { name: player }; else if (typeof player !== "object" || player === null) player = {}; - if (skillInfo && (typeof skillInfo !== "object" || Array.isArray(skillInfo))) - skillInfo = { audio: skillInfo }; + if (skillInfo && (typeof skillInfo !== "object" || Array.isArray(skillInfo))) skillInfo = { audio: skillInfo }; const checkSkill = (skill, history) => { if (!lib.skill[skill]) return false; if (!history.includes(skill)) return true; if (history[0] === skill) return false; //deadlock - throw new RangeError(`parseSkillAudio: ${skill} in ${ history }forms a deadlock`); + throw new RangeError(`parseSkillAudio: ${skill} in ${history}forms a deadlock`); }; - const getName = (filter) => { - const name = (player.tempname || []).find((i) => filter(i)); + const getName = filter => { + const name = (player.tempname || []).find(i => filter(i)); return ( name || [player.name, player.name1, player.name2].reduce((result, name) => { if (result) return result; if (!name) return result; if (filter(name)) return name; - let tempname = get.character(name).trashBin.find((tag) => tag.startsWith("tempname:")); + let tempname = (get.character(name).trashBin || []).find(tag => tag.startsWith("tempname:")); if (!tempname) return result; tempname = tempname .split(":") .slice(1) - .find((i) => filter(i)); + .find(i => filter(i)); return tempname || result; }, void 0) ); @@ -1567,7 +1500,7 @@ export class Game { history.unshift(skill); let audioInfo = info.audio; if (Array.isArray(info.audioname)) audioname.addArray(info.audioname); - if (info.audioname2) audioInfo = info.audioname2[getName((i) => info.audioname2[i])] || audioInfo; + if (info.audioname2) audioInfo = info.audioname2[getName(i => info.audioname2[i])] || audioInfo; if (typeof audioInfo === "function") audioInfo = audioInfo(player); return parseAudio(skill, options, audioInfo); @@ -1586,18 +1519,15 @@ export class Game { if (Array.isArray(audioInfo)) { if (typeof audioInfo[0] === "string" && typeof audioInfo[1] === "number") { // [audioname, number] - if (checkSkill(audioInfo[0], history)) - return getAudioList(audioInfo[0], options).slice(0, audioInfo[1]); + if (checkSkill(audioInfo[0], history)) return getAudioList(audioInfo[0], options).slice(0, audioInfo[1]); return parseAudio(audioInfo[0], options, audioInfo[1]); } return audioInfo.reduce((total, i) => total.addArray(parseAudio(skill, options, i)), []); } - if (!["string", "number", "boolean"].includes(typeof audioInfo)) - return parseAudio(skill, options, [true, 2]); + if (!["string", "number", "boolean"].includes(typeof audioInfo)) return parseAudio(skill, options, [true, 2]); if (audioInfo === false) return []; - if (typeof audioInfo === "string" && checkSkill(audioInfo, history)) - return getAudioList(audioInfo, options); + if (typeof audioInfo === "string" && checkSkill(audioInfo, history)) return getAudioList(audioInfo, options); audioInfo = String(audioInfo); let list = audioInfo.match(/(?:(.*):|^)(true|\d+)(?::(.*)|$)/); // [path, number|true, format] @@ -1605,25 +1535,20 @@ export class Game { let path = "", format = ""; if (!/^db:|^ext:|\//.test(audioInfo)) path = "skill/"; - if ( - !/\.\w+$/.test(audioInfo) && - !["data:", "blob:"].some((name) => audioInfo.startsWith(name)) - ) - format = ".mp3"; + if (!/\.\w+$/.test(audioInfo) && !["data:", "blob:"].some(name => audioInfo.startsWith(name))) format = ".mp3"; if (path && format) return parseAudio(audioInfo, options, [true, 2]); return [useRawAudio ? audioInfo : `${path}${audioInfo}${format}`]; } - let _audioname = getName((i) => audioname.includes(i)); + let _audioname = getName(i => audioname.includes(i)); _audioname = _audioname ? `_${_audioname}` : ""; - if (list[2] === "true") - return [`${list[1] || "skill"}/${skill}${_audioname}.${list[3] || "mp3"}`]; + if (list[2] === "true") return [`${list[1] || "skill"}/${skill}${_audioname}.${list[3] || "mp3"}`]; const audioList = []; list[2] = parseInt(list[2]); for (let i = 1; i <= list[2]; i++) { - if(useRawAudio) audioList.push(`${skill}${_audioname}${i}`); + if (useRawAudio) audioList.push(`${skill}${_audioname}${i}`); else audioList.push(`${list[1] || "skill"}/${skill}${_audioname}${i}.${list[3] || "mp3"}`); } return audioList; @@ -1640,12 +1565,12 @@ export class Game { * @param { skillInfo | audioInfo } [skillInfo] 预设的skillInfo/audioInfo(转为skillInfo),覆盖lib.skill[skill] * @returns { string[] } 语音地址列表 */ - parseSkillText(skill, player, skillInfo){ + parseSkillText(skill, player, skillInfo) { const audios = game.parseSkillAudio(skill, player, skillInfo, true); const voiceMap = []; audios.forEach(audioname => { const voiceText = lib.translate[`#${audioname}`]; - if(voiceText) voiceMap.push(voiceText); + if (voiceText) voiceMap.push(voiceText); }); return voiceMap; } @@ -1659,8 +1584,7 @@ export class Game { * @returns */ trySkillAudio(skill, player, directaudio, nobroadcast, skillInfo) { - if (!nobroadcast) - game.broadcast(game.trySkillAudio, skill, player, directaudio, nobroadcast, skillInfo); + if (!nobroadcast) game.broadcast(game.trySkillAudio, skill, player, directaudio, nobroadcast, skillInfo); const info = skillInfo || lib.skill[skill]; if (!info) return; if (!lib.config.background_speak) return; @@ -1762,19 +1686,10 @@ export class Game { const audio = get.dynamicVariable(lib.card[card.name].audio, card, sex); if (typeof audio == "string") { const audioInfo = audio.split(":"); - if (["blob:", "data:"].some((prefix) => audio.startsWith(prefix))) { + if (["blob:", "data:"].some(prefix => audio.startsWith(prefix))) { game.playAudio(audio); - } else if (audio.startsWith("db:")) - game.playAudio( - `${audioInfo[0]}:${audioInfo[1]}`, - audioInfo[2], - `${card.name}_${sex}.${audioInfo[3] || "mp3"}` - ); - else if (audio.startsWith("ext:")) - game.playAudio( - `${audioInfo[0]}:${audioInfo[1]}`, - `${card.name}_${sex}.${audioInfo[2] || "mp3"}` - ); + } else if (audio.startsWith("db:")) game.playAudio(`${audioInfo[0]}:${audioInfo[1]}`, audioInfo[2], `${card.name}_${sex}.${audioInfo[3] || "mp3"}`); + else if (audio.startsWith("ext:")) game.playAudio(`${audioInfo[0]}:${audioInfo[1]}`, `${card.name}_${sex}.${audioInfo[2] || "mp3"}`); else game.playAudio("card", sex, `${audioInfo[0]}.${audioInfo[1] || "mp3"}`); } else game.playAudio("card", sex, card.name); } @@ -1787,46 +1702,29 @@ export class Game { const aozhanBGMConfiguration = lib.config.mode_config.guozhan.aozhan_bgm; if (aozhanBGMConfiguration == "disabled") return; let aozhan = _status.tempAozhan || aozhanBGMConfiguration; - if (Array.isArray(aozhan)) - aozhan = aozhan.randomGet("disabled", _status.currentAozhan) || aozhanBGMConfiguration; - if (aozhan == "random") - aozhan = Object.keys(lib.mode.guozhan.config.aozhan_bgm.item).randomGet( - "disabled", - "random", - _status.currentAozhan - ); + if (Array.isArray(aozhan)) aozhan = aozhan.randomGet("disabled", _status.currentAozhan) || aozhanBGMConfiguration; + if (aozhan == "random") aozhan = Object.keys(lib.mode.guozhan.config.aozhan_bgm.item).randomGet("disabled", "random", _status.currentAozhan); _status.currentAozhan = aozhan; - if (["blob:", "data:"].some((prefix) => aozhan.startsWith(prefix))) { + if (["blob:", "data:"].some(prefix => aozhan.startsWith(prefix))) { ui.backgroundMusic.src = aozhan; - } else if (aozhan.startsWith("db:")) - game.getDB("image", aozhan.slice(3)).then((result) => (ui.backgroundMusic.src = result)); - else if (aozhan.startsWith("ext:")) - ui.backgroundMusic.src = `${lib.assetURL}extension/${aozhan.slice(4)}`; + } else if (aozhan.startsWith("db:")) game.getDB("image", aozhan.slice(3)).then(result => (ui.backgroundMusic.src = result)); + else if (aozhan.startsWith("ext:")) ui.backgroundMusic.src = `${lib.assetURL}extension/${aozhan.slice(4)}`; else ui.backgroundMusic.src = `${lib.assetURL}audio/background/aozhan_${aozhan}.mp3`; return; } let music = _status.tempMusic || lib.config.background_music; - if (Array.isArray(music)) - music = music.randomGet("music_off", _status.currentMusic) || lib.config.background_music; - if (music == "music_random") - music = lib.config.all.background_music.randomGet( - "music_off", - "music_random", - _status.currentMusic - ); + if (Array.isArray(music)) music = music.randomGet("music_off", _status.currentMusic) || lib.config.background_music; + if (music == "music_random") music = lib.config.all.background_music.randomGet("music_off", "music_random", _status.currentMusic); _status.currentMusic = music; if (music == "music_custom") { const backgroundMusicSourceConfiguration = lib.config.background_music_src; - if (backgroundMusicSourceConfiguration) - ui.backgroundMusic.src = backgroundMusicSourceConfiguration; + if (backgroundMusicSourceConfiguration) ui.backgroundMusic.src = backgroundMusicSourceConfiguration; return; } - if (["blob:", "data:"].some((prefix) => music.startsWith(prefix))) { + if (["blob:", "data:"].some(prefix => music.startsWith(prefix))) { ui.backgroundMusic.src = music; - } else if (music.startsWith("db:")) - game.getDB("image", music.slice(3)).then((result) => (ui.backgroundMusic.src = result)); - else if (music.startsWith("ext:")) - ui.backgroundMusic.src = `${lib.assetURL}extension/${music.slice(4)}`; + } else if (music.startsWith("db:")) game.getDB("image", music.slice(3)).then(result => (ui.backgroundMusic.src = result)); + else if (music.startsWith("ext:")) ui.backgroundMusic.src = `${lib.assetURL}extension/${music.slice(4)}`; else ui.backgroundMusic.src = `${lib.assetURL}audio/background/${music}.mp3`; } // 某种意义上,改不了,得重写 @@ -1911,7 +1809,7 @@ export class Game { */ import(type, content, url) { if (type == "extension") { - const promise = game.loadExtension(content).then((name) => { + const promise = game.loadExtension(content).then(name => { if (typeof _status.extensionLoaded == "undefined") _status.extensionLoaded = []; _status.extensionLoaded.add(name); return name; @@ -1921,9 +1819,7 @@ export class Game { return promise; } else { if (!lib.imported[type]) lib.imported[type] = {}; - const promise = Promise.resolve( - (gnc.is.generator(content) ? gnc.of(content) : content)(lib, game, ui, get, ai, _status) - ).then((content2) => { + const promise = Promise.resolve((gnc.is.generator(content) ? gnc.of(content) : content)(lib, game, ui, get, ai, _status)).then(content2 => { if (content2.name) { lib.imported[type][content2.name] = content2; delete content2.name; @@ -1938,14 +1834,7 @@ export class Game { async loadExtension(object) { let noEval = false; if (typeof object == "function") { - object = await (gnc.is.generatorFunc(object) ? gnc.of(object) : object)( - lib, - game, - ui, - get, - ai, - _status - ); + object = await (gnc.is.generatorFunc(object) ? gnc.of(object) : object)(lib, game, ui, get, ai, _status); noEval = true; } if (object.closeSyntaxCheck) { @@ -2008,8 +1897,7 @@ export class Game { name: "编辑此扩展", clear: true, onclick: () => { - if (game.editExtension && lib.extensionPack && lib.extensionPack[name]) - game.editExtension(name); + if (game.editExtension && lib.extensionPack && lib.extensionPack[name]) game.editExtension(name); else alert("无法编辑未启用的扩展,请启用此扩展并重启后重试"); }, }; @@ -2019,18 +1907,14 @@ export class Game { onclick: function () { if (this.innerHTML != "确认删除") { this.innerHTML = "确认删除"; - new Promise((resolve) => setTimeout(resolve, 1000)).then( - () => (this.innerHTML = "删除此扩展") - ); + new Promise(resolve => setTimeout(resolve, 1000)).then(() => (this.innerHTML = "删除此扩展")); return; } const page = this.parentNode, start = page.parentNode.previousSibling; page.remove(); if (start) { - const pageInStart = Array.from(start.childNodes).find( - (childNode) => childNode.link == page - ); + const pageInStart = Array.from(start.childNodes).find(childNode => childNode.link == page); if (pageInStart) { let active = false; if (pageInStart.classList.contains("active")) active = true; @@ -2054,8 +1938,7 @@ export class Game { if (!object || !libConfig[`${extensionName}_enable`]) return; if (!noEval) lib.init.eval(object); const config = Object.keys(libConfig).reduce((constructingConfig, key) => { - if (key != extensionName && key.startsWith(extensionName)) - constructingConfig[key.slice(11 + name.length)] = libConfig[key]; + if (key != extensionName && key.startsWith(extensionName)) constructingConfig[key.slice(11 + name.length)] = libConfig[key]; return constructingConfig; }, {}); try { @@ -2080,30 +1963,15 @@ export class Game { if (precontent) { _status.extension = name; - await (gnc.is.generatorFunc(precontent) ? gnc.of(precontent) : precontent).call( - object, - config - ); + await (gnc.is.generatorFunc(precontent) ? gnc.of(precontent) : precontent).call(object, config); delete _status.extension; } } catch (e1) { console.log(`加载《${name}》扩展的precontent时出现错误。`, e1); - if (!lib.config.extension_alert) - alert( - `加载《${name}》扩展的precontent时出现错误。\n该错误本身可能并不影响扩展运行。您可以在“设置→通用→无视扩展报错”中关闭此弹窗。\n${decodeURI( - e1.stack - )}` - ); + if (!lib.config.extension_alert) alert(`加载《${name}》扩展的precontent时出现错误。\n该错误本身可能并不影响扩展运行。您可以在“设置→通用→无视扩展报错”中关闭此弹窗。\n${decodeURI(e1.stack)}`); } - if (content) - lib.extensions.push([ - name, - content, - config, - _status.evaluatingExtension, - objectPackage || {}, - ]); + if (content) lib.extensions.push([name, content, config, _status.evaluatingExtension, objectPackage || {}]); } catch (e) { console.log(e); } @@ -2172,7 +2040,7 @@ export class Game { filelist2 = _filelist || []; if (_filelist) delete data._filelist; const filelist = Object.keys(data); - filelist.forEach((value) => zip.file(value, data[value])); + filelist.forEach(value => zip.file(value, data[value])); game.print(filelist); game.print(filelist2); const generate = zip.generate({ @@ -2183,22 +2051,14 @@ export class Game { return; } if (extensionPackage) { - extensionPackage.files = filelist - .concat(filelist2) - .filter((value) => value != "extension.js"); + extensionPackage.files = filelist.concat(filelist2).filter(value => value != "extension.js"); const size = generate.byteLength; if (size < 1000) extensionPackage.size = `${size}B`; else if (size < 1000000) extensionPackage.size = `${Math.round(size / 1000)}KB`; else extensionPackage.size = `${Math.round(size / 100000) / 10}MB`; zip.file( "package.js", - Object.keys(extensionPackage).reduce( - (constructingData, key, currentIndex, keys) => - `${constructingData}\t${key}:${JSON.stringify(extensionPackage[key])}${ - currentIndex < keys.length - 1 ? ",\n" : "\n};" - }`, - `extension["${exportExtension}"]={\n` - ) + Object.keys(extensionPackage).reduce((constructingData, key, currentIndex, keys) => `${constructingData}\t${key}:${JSON.stringify(extensionPackage[key])}${currentIndex < keys.length - 1 ? ",\n" : "\n};"}`, `extension["${exportExtension}"]={\n`) ); } const blob = zip.generate({ @@ -2207,13 +2067,10 @@ export class Game { fileNameToSaveAs = `${exportExtension.replace(/\\|\/|:|\?|"|\*|<|>|\|/g, "-")}.zip`; if (lib.device) { - const directory = - lib.device == "android" - ? cordova.file.externalDataDirectory - : cordova.file.documentsDirectory; + const directory = lib.device == "android" ? cordova.file.externalDataDirectory : cordova.file.documentsDirectory; new Promise((resolve, reject) => window.resolveLocalFileSystemURL(directory, resolve, reject)) .then( - (directoryEntry) => + directoryEntry => new Promise((resolve, reject) => directoryEntry.getFile( fileNameToSaveAs, @@ -2225,12 +2082,9 @@ export class Game { ) ) ) + .then(fileEntry => new Promise((resolve, reject) => fileEntry.createWriter(resolve, reject))) .then( - (fileEntry) => - new Promise((resolve, reject) => fileEntry.createWriter(resolve, reject)) - ) - .then( - (fileWriter) => + fileWriter => new Promise((resolve, reject) => { fileWriter.onerror = reject; fileWriter.onwriteend = resolve; @@ -2250,7 +2104,7 @@ export class Game { return; } //导入 - const UHP = (error) => { + const UHP = error => { if (!(error instanceof Error)) error = new Error(error); for (const [key, value] of Object.entries(Object.getOwnPropertyDescriptors(error))) { if (value.configurable === true) { @@ -2282,21 +2136,25 @@ export class Game { if (str === "" || str === undefined) throw "你导入的不是扩展!请选择正确的文件"; // 编译ts扩展 if (isTsFile) { - if (typeof globalThis.ts === 'undefined') { - await lib.init.promises.js('game', 'typescript'); + if (typeof globalThis.ts === "undefined") { + await lib.init.promises.js("game", "typescript"); } /** * @type {typeof import('typescript')} */ const ts = globalThis.ts; - str = ts.transpile(str, { - module: ts.ModuleKind.ES2015, - //@todo: ES2019 -> ES2020 - target: ts.ScriptTarget.ES2019, - inlineSourceMap: true, - resolveJsonModule: true, - esModuleInterop: true, - }, 'extension.ts'); + str = ts.transpile( + str, + { + module: ts.ModuleKind.ES2015, + //@todo: ES2019 -> ES2020 + target: ts.ScriptTarget.ES2019, + inlineSourceMap: true, + resolveJsonModule: true, + esModuleInterop: true, + }, + "extension.ts" + ); } _status.importingExtension = true; try { @@ -2311,16 +2169,16 @@ export class Game { // 是模块扩展 if ( // @ts-ignore - error.message === 'Cannot use import statement outside a module' || + error.message === "Cannot use import statement outside a module" || // @ts-ignore - error.message === 'await is only valid in async functions and the top level bodies of modules' + error.message === "await is only valid in async functions and the top level bodies of modules" ) { // 改为用info.json判断扩展名 const infoFile = zip.file("info.json"); if (!infoFile) throw new Error("未找到info.json,导入模块化扩展必须加入info.json!"); const info = JSON.parse(infoFile.asText()); - if (typeof info.name == 'string') { - await game.import('extension', () => { + if (typeof info.name == "string") { + await game.import("extension", () => { return Object.assign(info, { config: {}, }); @@ -2338,21 +2196,20 @@ export class Game { game.saveConfigValue("extensions"); game.saveConfig(`extension_${extensionName}_enable`, true); const config = game.importedPack.config; - Object.keys(config).forEach((value) => { + Object.keys(config).forEach(value => { const configObject = config[value]; - if (configObject && "init" in configObject) - game.saveConfig(`extension_${extensionName}_${value}`, configObject.init); + if (configObject && "init" in configObject) game.saveConfig(`extension_${extensionName}_${value}`, configObject.init); }); if (game.download) { const files = zip.files, hiddenFileFlags = [".", "_"], fileList = Object.keys(files) - .filter((key) => !files[key].dir && !hiddenFileFlags.includes(key[0])) + .filter(key => !files[key].dir && !hiddenFileFlags.includes(key[0])) .reverse(); //电脑端 //具备nodeJS环境 if (lib.node && lib.node.fs) { - const writeFile = (errnoException) => { + const writeFile = errnoException => { if (errnoException) { finishLoad(); UHP(errnoException); @@ -2364,30 +2221,16 @@ export class Game { const zipDir = fileList.pop(), fileName = zipDir.split("/"), name = fileName.pop(), - letGo = (name) => - new Promise((resolve) => - lib.node.fs.writeFile( - `${__dirname}/extension/${extensionName}/${name}`, - zip.file(zipDir).asNodeBuffer(), - null, - resolve - ) - ).then(writeFile); - return fileName.length - ? game.promises - .createDir(`extension/${extensionName}/${fileName.join("/")}`) - .then(() => letGo(`${fileName.join("/")}/${name}`)) - : letGo(name); + letGo = name => new Promise(resolve => lib.node.fs.writeFile(`${__dirname}/extension/${extensionName}/${name}`, zip.file(zipDir).asNodeBuffer(), null, resolve)).then(writeFile); + return fileName.length ? game.promises.createDir(`extension/${extensionName}/${fileName.join("/")}`).then(() => letGo(`${fileName.join("/")}/${name}`)) : letGo(name); } finishLoad(); }; game.promises.ensureDirectory(`extension/${extensionName}`).then(writeFile).catch(UHP); } else - new Promise((resolve, reject) => - window.resolveLocalFileSystemURL(nonameInitialized, resolve, reject) - ) + new Promise((resolve, reject) => window.resolveLocalFileSystemURL(nonameInitialized, resolve, reject)) .then( - (directoryEntry) => + directoryEntry => new Promise((resolve, reject) => directoryEntry.getDirectory( `extension/${extensionName}`, @@ -2399,7 +2242,7 @@ export class Game { ) ) ) - .then((directoryEntry) => { + .then(directoryEntry => { //扩展文件夹 const writeFile = () => { if (!fileList.length) { @@ -2410,7 +2253,7 @@ export class Game { const zipDirectory = fileList.shift(), fileName = zipDirectory.split("/"), name = fileName.pop(), - letGo = (name) => + letGo = name => new Promise((resolve, reject) => directoryEntry.getFile( name, @@ -2421,28 +2264,17 @@ export class Game { reject ) ) + .then(fileEntry => new Promise((resolve, reject) => fileEntry.createWriter(resolve, reject))) .then( - (fileEntry) => - new Promise((resolve, reject) => - fileEntry.createWriter(resolve, reject) - ) - ) - .then( - (fileWriter) => + fileWriter => new Promise((resolve, reject) => { fileWriter.onerror = reject; fileWriter.onwriteend = resolve; - fileWriter.write( - zip.file(zipDirectory).asArrayBuffer() - ); + fileWriter.write(zip.file(zipDirectory).asArrayBuffer()); }) ) .then(writeFile); - return fileName.length - ? game.promises - .createDir(`extension/${extensionName}/${fileName.join("/")}`) - .then(() => letGo(`${fileName.join("/")}/${name}`)) - : letGo(name); + return fileName.length ? game.promises.createDir(`extension/${extensionName}/${fileName.join("/")}`).then(() => letGo(`${fileName.join("/")}/${name}`)) : letGo(name); }; return writeFile(); }) @@ -2450,16 +2282,13 @@ export class Game { } else { localStorage.setItem(`${lib.configprefix}extension_${extensionName}`, str); const hiddenFileFlags = [".", "_"], - fileList = Object.keys(zip.files).filter( - (filePath) => - !hiddenFileFlags.includes(filePath[0]) && filePath[filePath.length - 1] != "/" - ); + fileList = Object.keys(zip.files).filter(filePath => !hiddenFileFlags.includes(filePath[0]) && filePath[filePath.length - 1] != "/"); if (fileList.length && lib.db) { lib.config.extensionInfo[extensionName] = { file: fileList, }; game.saveConfigValue("extensionInfo"); - fileList.forEach((filePath) => { + fileList.forEach(filePath => { const arrayBuffer = zip.file(filePath).asArrayBuffer(); if (!arrayBuffer) return; const blob = new Blob([arrayBuffer]); @@ -2468,13 +2297,7 @@ export class Game { fileReader.onerror = reject; fileReader.onload = resolve; fileReader.readAsDataURL(blob, "UTF-8"); - }).then((fileLoadedEvent) => - game.putDB( - "image", - `extension-${extensionName}:${filePath}`, - fileLoadedEvent.target.result - ) - ); + }).then(fileLoadedEvent => game.putDB("image", `extension-${extensionName}:${filePath}`, fileLoadedEvent.target.result)); }); } finishLoad(); @@ -2747,12 +2570,7 @@ export class Game { if (_status.mode == "stratagem") { game.players[i].init(players[i].name, players[i].name2); game.players[i].identity = players[i].identity; - if ( - (game.players[i].identity == "fan" && - game.players[i].isCamouflaged && - game.me.identity == "nei") || - game.players[i] == game.me - ) { + if ((game.players[i].identity == "fan" && game.players[i].isCamouflaged && game.me.identity == "nei") || game.players[i] == game.me) { game.players[i].setIdentity(players[i].identity); } } else { @@ -3115,14 +2933,7 @@ export class Game { player.tempname.add(map.to); player.skin[name] = map.to; const goon = !lib.character[map.to]; - if (goon) - lib.character[map.to] = [ - "", - "", - 0, - [], - (map.list.find((i) => i[0] == map.to) || [map.to, []])[1], - ]; + if (goon) lib.character[map.to] = ["", "", 0, [], (map.list.find(i => i[0] == map.to) || [map.to, []])[1]]; player.smoothAvatar(map.avatar2); player.node["avatar" + map.name.slice(4)].setBackground(map.to, "character"); player.node["avatar" + map.name.slice(4)].show(); @@ -3199,11 +3010,7 @@ export class Game { player.classList.remove("unseen2_v"); break; } - if ( - !player.classList.contains("unseen_v") && - (!player.name2 || !player.classList.contains("unseen2_v")) && - player.storage.nohp - ) { + if (!player.classList.contains("unseen_v") && (!player.name2 || !player.classList.contains("unseen2_v")) && player.storage.nohp) { delete player.storage.nohp; player.node.hp.show(); player.update(); @@ -3281,11 +3088,7 @@ export class Game { }, compareMultiple: function (player, info) { if (player && info) { - player.$compareMultiple( - get.infoCard(info[0]), - get.infoTargets(info[1]), - get.infoCards(info[2]) - ); + player.$compareMultiple(get.infoCard(info[0]), get.infoTargets(info[1]), get.infoCards(info[2])); } else { console.log(player); } @@ -3327,11 +3130,7 @@ export class Game { } for (var i = 0; i < cards.length; i++) { for (var j = 0; j < nodes.length; j++) { - if ( - cards[i][2] == nodes[j].name && - cards[i][0] == nodes[j].suit && - cards[i][1] == nodes[j].number - ) { + if (cards[i][2] == nodes[j].name && cards[i][0] == nodes[j].suit && cards[i][1] == nodes[j].number) { nodes[j].moveDelete(player); cards.splice(i--, 1); nodes.splice(j--, 1); @@ -3355,11 +3154,7 @@ export class Game { } for (var i = 0; i < cards.length; i++) { for (var j = 0; j < nodes.length; j++) { - if ( - cards[i][2] == nodes[j].name && - cards[i][0] == nodes[j].suit && - cards[i][1] == nodes[j].number - ) { + if (cards[i][2] == nodes[j].name && cards[i][0] == nodes[j].suit && cards[i][1] == nodes[j].number) { nodes[j].delete(); if (method == "zoom") { nodes[j].style.transform = "scale(0)"; @@ -3454,11 +3249,7 @@ export class Game { var checkMatch = function (l1, l2) { for (var i = 0; i < l1.length; i++) { for (var j = 0; j < l2.length; j++) { - if ( - l2[j].suit == l1[i][0] && - l2[j].number == l1[i][1] && - l2[j].name == l1[i][2] - ) { + if (l2[j].suit == l1[i][0] && l2[j].number == l1[i][1] && l2[j].name == l1[i][2]) { l2[j].addGaintag(content[1]); l2.splice(j--, 1); break; @@ -3667,14 +3458,9 @@ export class Game { if (player && content) { var card = get.infoCard(content[0]); card.viewAs = content[1]; - if ( - card.viewAs && - card.viewAs != card.name && - (card.classList.contains("fullskin") || card.classList.contains("fullborder")) - ) { + if (card.viewAs && card.viewAs != card.name && (card.classList.contains("fullskin") || card.classList.contains("fullborder"))) { card.classList.add("fakejudge"); - card.node.background.innerHTML = - lib.translate[card.viewAs + "_bg"] || get.translation(card.viewAs)[0]; + card.node.background.innerHTML = lib.translate[card.viewAs + "_bg"] || get.translation(card.viewAs)[0]; } card.classList.add("drawinghidden"); player.node.judges.insertBefore(card, player.node.judges.firstChild); @@ -3774,11 +3560,7 @@ export class Game { var checkMatch = function (l1, l2) { for (var i = 0; i < l1.length; i++) { for (var j = 0; j < l2.length; j++) { - if ( - l2[j].suit == l1[i][0] && - l2[j].number == l1[i][1] && - l2[j].name == l1[i][2] - ) { + if (l2[j].suit == l1[i][0] && l2[j].number == l1[i][1] && l2[j].name == l1[i][2]) { l2[j].remove(); l2.splice(j--, 1); break; @@ -4467,35 +4249,15 @@ export class Game { surface.beginPath(); var middle = 0.5; var radius = p.radius; - if ( - type == "recover" || - type == "legend" || - type == "rare" || - type == "epic" || - type == "coin" || - type == "dust" - ) { + if (type == "recover" || type == "legend" || type == "rare" || type == "epic" || type == "coin" || type == "dust") { middle = 0.7; radius /= 3; } p.opacity = Math.round((p.death / p.life) * 100) / 100; - var gradient = surface.createRadialGradient( - p.location.x, - p.location.y, - 0, - p.location.x, - p.location.y, - p.radius - ); - gradient.addColorStop( - 0, - "rgba(" + p.r + ", " + p.g + ", " + p.b + ", " + p.opacity + ")" - ); - gradient.addColorStop( - middle, - "rgba(" + p.r + ", " + p.g + ", " + p.b + ", " + p.opacity + ")" - ); + var gradient = surface.createRadialGradient(p.location.x, p.location.y, 0, p.location.x, p.location.y, p.radius); + gradient.addColorStop(0, "rgba(" + p.r + ", " + p.g + ", " + p.b + ", " + p.opacity + ")"); + gradient.addColorStop(middle, "rgba(" + p.r + ", " + p.g + ", " + p.b + ", " + p.opacity + ")"); gradient.addColorStop(1, "rgba(" + p.r + ", " + p.g + ", " + p.b + ", 0)"); surface.fillStyle = gradient; surface.arc(p.location.x, p.location.y, radius, Math.PI * 2, false); @@ -4539,7 +4301,7 @@ export class Game { dashed = false, drag = false; if (arguments[1] && typeof arguments[1] == "object") - Object.keys(arguments[1]).forEach((value) => { + Object.keys(arguments[1]).forEach(value => { switch (value) { case "opacity": opacity = arguments[1][value]; @@ -4646,19 +4408,11 @@ export class Game { let current; if (time < total / 3) { ctx.strokeStyle = "rgba(" + color.toString() + "," + opacity * (time / (total / 3)) + ")"; - current = [ - from[0] + ((to[0] - from[0]) * time) / (total / 3), - from[1] + ((to[1] - from[1]) * time) / (total / 3), - ]; + current = [from[0] + ((to[0] - from[0]) * time) / (total / 3), from[1] + ((to[1] - from[1]) * time) / (total / 3)]; } else if (time <= total) { current = to; if (time > total / 1.5) { - ctx.strokeStyle = - "rgba(" + - color.toString() + - "," + - opacity * (1 - (time - total / 1.5) / (total - total / 1.5)) + - ")"; + ctx.strokeStyle = "rgba(" + color.toString() + "," + opacity * (1 - (time - total / 1.5) / (total - total / 1.5)) + ")"; } else { ctx.strokeStyle = "rgba(" + color.toString() + "," + opacity + ")"; } @@ -4724,18 +4478,7 @@ export class Game { addCharacter(name, information) { //TODO: 这一坨也要改 const extensionName = _status.extension || information.extension, - character = [ - information.sex, - information.group, - information.hp, - information.skills || [], - [ - _status.evaluatingExtension - ? `db:extension-${extensionName}:${name}.jpg` - : `ext:${extensionName}/${name}.jpg`, - `die:ext:${extensionName}/${name}.mp3`, - ], - ]; + character = [information.sex, information.group, information.hp, information.skills || [], [_status.evaluatingExtension ? `db:extension-${extensionName}:${name}.jpg` : `ext:${extensionName}/${name}.jpg`, `die:ext:${extensionName}/${name}.mp3`]]; if (information.tags) character[4] = character[4].concat(information.tags); lib.character[name] = character; const packName = `mode_extension_${extensionName}`; @@ -4771,15 +4514,8 @@ export class Game { imgsrc = "ext:" + extname + "/" + j + ".jpg"; } const audiosrc = "die:ext:" + extname + "/" + j + ".mp3"; - if ( - !pack[i][j][4].some( - (str) => - typeof str == "string" && /^(?:db:extension-.+?|ext|img):(?:.+)/.test(str) - ) - ) - pack[i][j][4].add(imgsrc); - if (!pack[i][j][4].some((str) => typeof str == "string" && /^die:(?:.+)/.test(str))) - pack[i][j][4].add(audiosrc); + if (!pack[i][j][4].some(str => typeof str == "string" && /^(?:db:extension-.+?|ext|img):(?:.+)/.test(str))) pack[i][j][4].add(imgsrc); + if (!pack[i][j][4].some(str => typeof str == "string" && /^die:(?:.+)/.test(str))) pack[i][j][4].add(audiosrc); if (pack[i][j][4].includes("boss") || pack[i][j][4].includes("hiddenboss")) { lib.config.forbidai.add(j); } @@ -4849,11 +4585,7 @@ export class Game { suits = ["club", "spade"]; } for (let i = 0; i < info2.number; i++) { - lib.card.list.push([ - suits[Math.floor(Math.random() * suits.length)], - Math.ceil(Math.random() * 13), - name, - ]); + lib.card.list.push([suits[Math.floor(Math.random() * suits.length)], Math.ceil(Math.random() * 13), name]); } } let packname = "mode_extension_" + extname; @@ -5099,7 +4831,7 @@ export class Game { */ removeExtension(extensionName, keepFile) { const prefix = `extension_${extensionName}`; - Object.keys(lib.config).forEach((key) => { + Object.keys(lib.config).forEach(key => { if (key.startsWith(prefix)) game.saveConfig(key); }); localStorage.removeItem(`${lib.configprefix}${prefix}`); @@ -5108,10 +4840,7 @@ export class Game { game.saveConfig("extensions", lib.config.extensions); const modeList = lib.config.extensionInfo[extensionName]; if (modeList) { - if (modeList.file) - Object.values(modeList.file).forEach((filePath) => - game.deleteDB("image", `extension-${extensionName}:${filePath}`) - ); + if (modeList.file) Object.values(modeList.file).forEach(filePath => game.deleteDB("image", `extension-${extensionName}:${filePath}`)); if (modeList.mode) Object.values(modeList.mode).forEach(game.clearModeConfig); delete lib.config.extensionInfo[extensionName]; game.saveConfigValue("extensionInfo"); @@ -5470,9 +5199,7 @@ export class Game { for (i = 0; i < game.players.length; i++) { tr = document.createElement("tr"); td = document.createElement("td"); - td.innerHTML = - get.translation(game.players[i]) + - (game.players[i].ai.stratagem_camouflage ? "(被伪装)" : ""); + td.innerHTML = get.translation(game.players[i]) + (game.players[i].ai.stratagem_camouflage ? "(被伪装)" : ""); tr.appendChild(td); td = document.createElement("td"); num = 0; @@ -5542,8 +5269,7 @@ export class Game { for (i = 0; i < game.dead.length; i++) { tr = document.createElement("tr"); td = document.createElement("td"); - td.innerHTML = - get.translation(game.dead[i]) + (game.dead[i].ai.stratagem_camouflage ? "(被伪装)" : ""); + td.innerHTML = get.translation(game.dead[i]) + (game.dead[i].ai.stratagem_camouflage ? "(被伪装)" : ""); tr.appendChild(td); td = document.createElement("td"); num = 0; @@ -5598,24 +5324,21 @@ export class Game { td = document.createElement("td"); num = 0; for (j = 0; j < game.additionaldead[i].stat.length; j++) { - if (game.additionaldead[i].stat[j].damage != undefined) - num += game.additionaldead[i].stat[j].damage; + if (game.additionaldead[i].stat[j].damage != undefined) num += game.additionaldead[i].stat[j].damage; } td.innerHTML = num; tr.appendChild(td); td = document.createElement("td"); num = 0; for (j = 0; j < game.additionaldead[i].stat.length; j++) { - if (game.additionaldead[i].stat[j].damaged != undefined) - num += game.additionaldead[i].stat[j].damaged; + if (game.additionaldead[i].stat[j].damaged != undefined) num += game.additionaldead[i].stat[j].damaged; } td.innerHTML = num; tr.appendChild(td); td = document.createElement("td"); num = 0; for (j = 0; j < game.additionaldead[i].stat.length; j++) { - if (game.additionaldead[i].stat[j].gain != undefined) - num += game.additionaldead[i].stat[j].gain; + if (game.additionaldead[i].stat[j].gain != undefined) num += game.additionaldead[i].stat[j].gain; } td.innerHTML = num; tr.appendChild(td); @@ -5631,8 +5354,7 @@ export class Game { td = document.createElement("td"); num = 0; for (j = 0; j < game.additionaldead[i].stat.length; j++) { - if (game.additionaldead[i].stat[j].kill != undefined) - num += game.additionaldead[i].stat[j].kill; + if (game.additionaldead[i].stat[j].kill != undefined) num += game.additionaldead[i].stat[j].kill; } td.innerHTML = num; tr.appendChild(td); @@ -5654,8 +5376,7 @@ export class Game { dialog.add(ui.create.div(".placeholder")); for (let i = 0; i < game.players.length; i++) { - if (!_status.connectMode && game.players[i].isUnderControl(true) && game.layout != "long2") - continue; + if (!_status.connectMode && game.players[i].isUnderControl(true) && game.layout != "long2") continue; let hs = game.players[i].getCards("h"); if (hs.length) { dialog.add('
' + get.translation(game.players[i]) + "
"); @@ -5809,13 +5530,7 @@ export class Game { game.reload(); }); } - } else if ( - !_status.connectMode && - get.config("continue_game") && - !ui.continue_game && - !_status.brawl && - !game.no_continue_game - ) { + } else if (!_status.connectMode && get.config("continue_game") && !ui.continue_game && !_status.brawl && !game.no_continue_game) { ui.continue_game = ui.create.control("再战", game.reloadCurrent); } } @@ -5856,12 +5571,7 @@ export class Game { } if (window.isNonameServer) { lib.configOL.gameStarted = false; - game.saveConfig("pagecfg" + window.isNonameServer, [ - lib.configOL, - game.roomId, - _status.onlinenickname, - _status.onlineavatar, - ]); + game.saveConfig("pagecfg" + window.isNonameServer, [lib.configOL, game.roomId, _status.onlinenickname, _status.onlineavatar]); game.reload(); } else if (_status.connectMode && !game.online) { setTimeout(game.reload, 15000); @@ -5889,24 +5599,8 @@ export class Game { belongAsyncEvent = game.belongAsyncEventList.at(-1); } while (true) { - let event = - belongAsyncEvent && belongAsyncEvent.parent == _status.event - ? belongAsyncEvent - : _status.event; - let { - step, - source, - player, - target, - targets, - card, - cards, - skill, - forced, - num, - _trigger: trigger, - _result: result, - } = event; + let event = belongAsyncEvent && belongAsyncEvent.parent == _status.event ? belongAsyncEvent : _status.event; + let { step, source, player, target, targets, card, cards, skill, forced, num, _trigger: trigger, _result: result } = event; const _resolve = () => { if (event.async) { if (typeof event.resolve == "function") { @@ -5961,8 +5655,7 @@ export class Game { if (next.player && next.player.skipList.includes(next.name)) { event.trigger(next.name + "Skipped"); next.player.skipList.remove(next.name); - if (lib.phaseName.includes(next.name)) - next.player.getHistory("skipped").add(next.name); + if (lib.phaseName.includes(next.name)) next.player.getHistory("skipped").add(next.name); } else { next.parent = event; _status.event = next; @@ -6010,12 +5703,7 @@ export class Game { }); if (typeof event.step == "number") ++event.step; }; - if ( - player && - player.classList.contains("dead") && - !event.forceDie && - event.name != "phaseLoop" - ) { + if (player && player.classList.contains("dead") && !event.forceDie && event.name != "phaseLoop") { game.broadcastAll(function () { while (_status.dieClose.length) { _status.dieClose.shift().close(); @@ -6038,12 +5726,8 @@ export class Game { } else { await game .runContent(belongAsyncEvent) - .catch((e) => { - if ( - _status.withError || - lib.config.compatiblemode || - (_status.connectMode && !lib.config.debug) - ) { + .catch(e => { + if (_status.withError || lib.config.compatiblemode || (_status.connectMode && !lib.config.debug)) { game.print("游戏出错:" + event.name); game.print(e.toString()); console.log(e); @@ -6064,26 +5748,9 @@ export class Game { * @param { GameEventPromise } [belongAsyncEvent] */ runContent(belongAsyncEvent) { - return new Promise((resolve) => { - let event = - belongAsyncEvent && belongAsyncEvent.parent == _status.event - ? belongAsyncEvent - : _status.event; - let { - step, - source, - player, - target, - targets, - card, - cards, - skill, - forced, - num, - _trigger: trigger, - _result: result, - _storeEvent, - } = event; + return new Promise(resolve => { + let event = belongAsyncEvent && belongAsyncEvent.parent == _status.event ? belongAsyncEvent : _status.event; + let { step, source, player, target, targets, card, cards, skill, forced, num, _trigger: trigger, _result: result, _storeEvent } = event; // 数组形式 if ("contents" in event && Array.isArray(event.contents)) { /* @@ -6101,15 +5768,10 @@ export class Game { }); */ // 解决不了问题...就把问题统一 - const run = async (event) => { + const run = async event => { if (typeof event.step !== "number") event.step = 0; while (event.step < event.contents.length && !event.finished) { - const evt = await event.contents[event.step]( - event, - event._trigger, - event.player, - event._tmpStoreEvent - ); + const evt = await event.contents[event.step](event, event._trigger, event.player, event._tmpStoreEvent); if (evt) event._tmpStoreEvent = evt; if (game.executingAsyncEventMap.has(event.toEvent())) { @@ -6154,34 +5816,14 @@ export class Game { } else if (event.content instanceof GeneratorFunction) { if (!event.debugging) { if (event.generatorContent) event.generatorContent.return(); - event.generatorContent = event.content( - event, - step, - source, - player, - target, - targets, - card, - cards, - skill, - forced, - num, - trigger, - result, - _status, - lib, - game, - ui, - get, - ai - ); + event.generatorContent = event.content(event, step, source, player, target, targets, card, cards, skill, forced, num, trigger, result, _status, lib, game, ui, get, ai); } else { delete event.debugging; } var next = event.generatorContent.next(); if (typeof next.value == "function" && next.value.toString() == "code=>eval(code)") { //触发debugger - var inputCallback = (inputResult) => { + var inputCallback = inputResult => { if (inputResult === false) { event.debugging = true; game.resume2(); @@ -6227,27 +5869,7 @@ export class Game { } }); } else { - event.content( - event, - step, - source, - player, - target, - targets, - card, - cards, - skill, - forced, - num, - trigger, - result, - _status, - lib, - game, - ui, - get, - ai - ); + event.content(event, step, source, player, target, targets, card, cards, skill, forced, num, trigger, result, _status, lib, game, ui, get, ai); resolve(); } }); @@ -6385,20 +6007,15 @@ export class Game { auto = true, auto_confirm = lib.config.auto_confirm; const player = event.player; - const uppercaseType = (type) => type[0].toUpperCase() + type.slice(1); + const uppercaseType = type => type[0].toUpperCase() + type.slice(1); - if ( - !event.filterButton && - !event.filterCard && - !event.filterTarget && - (!event.skill || !event._backup) - ) { + if (!event.filterButton && !event.filterCard && !event.filterTarget && (!event.skill || !event._backup)) { if (event.choosing) _status.imchoosing = true; return false; } let useCache = !lib.config.compatiblemode && !event.skill && !event.multitarget; - const filterCache = (type) => { + const filterCache = type => { if (get.select(event[`select${uppercaseType(type)}`])[1] < 0) return false; const cardinfo = get.info(get.card() || {}); if (cardinfo && cardinfo.complexTarget) return false; @@ -6406,7 +6023,7 @@ export class Game { return !event[`complex${uppercaseType(type)}`]; }; - ["button", "card", "target"].forEach((type) => { + ["button", "card", "target"].forEach(type => { if (!event[`filter${uppercaseType(type)}`]) return; if (!filterCache(type)) useCache = false; if (!ok) game.uncheck(type); @@ -6429,15 +6046,7 @@ export class Game { } player.node.equips.classList.remove("popequip"); - if ( - event.filterCard && - lib.config.popequip && - !_status.nopopequip && - get.is.phoneLayout() && - typeof event.position === "string" && - event.position.includes("e") && - player.node.equips.querySelector(".card.selectable") - ) { + if (event.filterCard && lib.config.popequip && !_status.nopopequip && get.is.phoneLayout() && typeof event.position === "string" && event.position.includes("e") && player.node.equips.querySelector(".card.selectable")) { player.node.equips.classList.add("popequip"); auto_confirm = false; } @@ -6445,7 +6054,7 @@ export class Game { if (event.isMine() && game.chess && get.config("show_distance") && game.me) { const players = game.players.slice(); if (event.deadTarget) players.addArray(game.dead); - players.forEach((player) => { + players.forEach(player => { if (player === game.me) return player.node.action.hide(); player.node.action.show(); let dist = get.distance(game.me, player, "pure"); @@ -6485,12 +6094,12 @@ export class Game { if (game.chess) { const shadows = Array.from(ui.chessContainer.querySelectorAll(".playergrid.temp")); - shadows.forEach((i) => i.remove()); + shadows.forEach(i => i.remove()); } if (event.player) event.player.node.equips.classList.remove("popequip"); if (args.includes("button") && event.dialog && event.dialog.buttons) { - event.dialog.buttons.forEach((button) => { + event.dialog.buttons.forEach(button => { button.classList.remove("selectable"); button.classList.remove("selected"); game.callHook("uncheckButton", [button, event]); @@ -6499,7 +6108,7 @@ export class Game { } if (args.includes("card") && event.player) { const cards = event.player.getCards("hejsx"); - cards.forEach((card) => { + cards.forEach(card => { card.classList.remove("selected"); card.classList.remove("selectable"); card.updateTransform(false); @@ -6508,7 +6117,7 @@ export class Game { ui.selected.cards.length = 0; } if (args.includes("target")) { - players.forEach((target) => { + players.forEach(target => { target.classList.remove("selected"); target.classList.remove("selectable"); game.callHook("uncheckTarget", [target, event]); @@ -6523,13 +6132,13 @@ export class Game { _status.mousedragging = null; _status.mousedragorigin = null; - ui.touchlines.forEach((i) => i.delete()); + ui.touchlines.forEach(i => i.delete()); ui.touchlines.length = 0; } ui.canvas.width = ui.arena.offsetWidth; ui.canvas.height = ui.arena.offsetHeight; - players.forEach((i) => i.unprompt()); - _status.dragline.forEach((i) => i && i.remove()); + players.forEach(i => i.unprompt()); + _status.dragline.forEach(i => i && i.remove()); _status.dragline.length = 0; ui.arena.classList.remove("dragging"); @@ -6662,7 +6271,7 @@ export class Game { game.me.setIdentity(game.me.identity); } setTimeout( - (players) => { + players => { for (let i = 0; i < players.length; i++) { players[i].style.transition = ""; } @@ -6756,10 +6365,7 @@ export class Game { if (lib.config.layout != game.layout) { lib.init.layout(lib.config.layout); } else if (lib.config.mode == "brawl") { - if ( - lib.config.player_border == "normal" && - (game.layout == "long" || game.layout == "long2") - ) { + if (lib.config.player_border == "normal" && (game.layout == "long" || game.layout == "long2")) { ui.arena.classList.add("lslim_player"); } } @@ -6890,10 +6496,7 @@ export class Game { if (!lib.card[lib.card.list[i][2]]) { lib.card.list.splice(i, 1); i--; - } else if ( - lib.card[lib.card.list[i][2]].mode && - lib.card[lib.card.list[i][2]].mode.includes(lib.config.mode) == false - ) { + } else if (lib.card[lib.card.list[i][2]].mode && lib.card[lib.card.list[i][2]].mode.includes(lib.config.mode) == false) { lib.card.list.splice(i, 1); i--; } @@ -7065,10 +6668,7 @@ export class Game { for (let i = 0; i < list.length; i++) { if (Math.random() < 0.7 || i == list.length - 1) { if (friend) { - event.moveAvatar( - list[i], - event.friend.length + event.config.width * (event.config.height - 1) - ); + event.moveAvatar(list[i], event.friend.length + event.config.width * (event.config.height - 1)); event.friend.push(list[i]); } else { event.moveAvatar(list[i], event.enemy.length); @@ -7102,13 +6702,8 @@ export class Game { let width = event.width, height = event.height, margin = event.margin; - let left = - (-(width + 10) * event.config.width) / 2 + 5 + (i % event.config.width) * (width + 10); - let top = - (-(height + 10) * event.config.height) / 2 + - 5 + - Math.floor(i / event.config.width) * (height + 10) + - margin / 2; + let left = (-(width + 10) * event.config.width) / 2 + 5 + (i % event.config.width) * (width + 10); + let top = (-(height + 10) * event.config.height) / 2 + 5 + Math.floor(i / event.config.width) * (height + 10) + margin / 2; node.style.transform = "translate(" + left + "px," + top + "px)"; node.index = i; }; @@ -7117,8 +6712,7 @@ export class Game { if (!get.is.phoneLayout()) { margin = 38; } - let height = - (ui.window.offsetHeight - 10 * (event.config.height + 1) - margin) / event.config.height; + let height = (ui.window.offsetHeight - 10 * (event.config.height + 1) - margin) / event.config.height; let width = (ui.window.offsetWidth - 10 * (event.config.width + 1)) / event.config.width; if (width * event.config.ratio < height) { height = width * event.config.ratio; @@ -7136,19 +6730,13 @@ export class Game { event.moveNode(event.avatars[i], event.avatars[i].index); event.avatars[i].style.width = width + "px"; event.avatars[i].style.height = height + "px"; - event.avatars[i].nodename.style.fontSize = - Math.max(14, Math.round(width / 5.6)) + "px"; + event.avatars[i].nodename.style.fontSize = Math.max(14, Math.round(width / 5.6)) + "px"; } } if (event.deciding) { let str = "px," + (event.margin / 2 - event.height * 0.5) + "px)"; for (let i = 0; i < event.friendlist.length; i++) { - event.friendlist[i].style.transform = - "scale(1.2) translate(" + - ((-(event.width + 14) * event.friendlist.length) / 2 + - 7 + - i * (event.width + 14)) + - str; + event.friendlist[i].style.transform = "scale(1.2) translate(" + ((-(event.width + 14) * event.friendlist.length) / 2 + 7 + i * (event.width + 14)) + str; } } }; @@ -7170,19 +6758,12 @@ export class Game { } if (event.config.update) { for (let i = 0; i < event.friendlist.length; i++) { - event.friendlist[i].nodename.innerHTML = - event.config.update(i, event.friendlist.length) || - event.friendlist[i].nodename.innerHTML; + event.friendlist[i].nodename.innerHTML = event.config.update(i, event.friendlist.length) || event.friendlist[i].nodename.innerHTML; } } let str = "px," + (event.margin / 2 - event.height * 0.5) + "px)"; for (let i = 0; i < event.friendlist.length; i++) { - event.friendlist[i].style.transform = - "scale(1.2) translate(" + - ((-(event.width + 14) * event.friendlist.length) / 2 + - 7 + - i * (event.width + 14)) + - str; + event.friendlist[i].style.transform = "scale(1.2) translate(" + ((-(event.width + 14) * event.friendlist.length) / 2 + 7 + i * (event.width + 14)) + str; } } else { if (!event.imchoosing) return; @@ -7199,10 +6780,7 @@ export class Game { } } if (this.classList.contains("moved")) return; - event.moveAvatar( - this, - event.friend.length + event.config.width * (event.config.height - 1) - ); + event.moveAvatar(this, event.friend.length + event.config.width * (event.config.height - 1)); event.friend.push(this.link); this.classList.add("moved"); game.resume(); @@ -7367,12 +6945,7 @@ export class Game { if (!event.list2) { event.list2 = event.list.randomGets(event.config.width * 2); for (let i = 0; i < event.config.width * 2; i++) { - event.avatars.push( - ui.create.div( - ".shadowed.shadowed2.reduce_radius.character.choosedouble", - event.clickAvatar - ) - ); + event.avatars.push(ui.create.div(".shadowed.shadowed2.reduce_radius.character.choosedouble", event.clickAvatar)); let name = event.list2[i]; event.avatars[i].setBackground(name, "character"); event.avatars[i].link = name; @@ -7454,10 +7027,7 @@ export class Game { for (let i = 0; i < event.avatars.length; i++) { if (!event.avatars[i].classList.contains("moved")) { if (event.side < 2) { - event.moveAvatar( - event.avatars[i], - event.friend.length + event.config.width * (event.config.height - 1) - ); + event.moveAvatar(event.avatars[i], event.friend.length + event.config.width * (event.config.height - 1)); event.friend.push(event.avatars[i]); } else { event.moveAvatar(event.avatars[i], event.enemy.length); @@ -7570,21 +7140,15 @@ export class Game { if (info.alter) { lib.translate[`${iInfo}_origin`] = lib.translate[iInfo]; if (!lib.config.vintageSkills.includes(i)) lib.translate[iInfo] = lib.translate[`${iInfo}_alter`]; - } else if (_status.mode && lib.translate[iInfo + "_" + mode + "_" + _status.mode]) - lib.translate[iInfo] = lib.translate[iInfo + "_" + mode + "_" + _status.mode]; + } else if (_status.mode && lib.translate[iInfo + "_" + mode + "_" + _status.mode]) lib.translate[iInfo] = lib.translate[iInfo + "_" + mode + "_" + _status.mode]; else if (lib.translate[`${iInfo}_${mode}`]) lib.translate[iInfo] = lib.translate[`${iInfo}_${mode}`]; - else if ( - lib.translate[`${iInfo}_zhu`] && - (mode == "identity" || (mode == "guozhan" && _status.mode == "four")) - ) - lib.translate[iInfo] = lib.translate[`${iInfo}_zhu`]; - else if (lib.translate[`${iInfo}_combat`] && get.is.versus()) - lib.translate[iInfo] = lib.translate[`${iInfo}_combat`]; + else if (lib.translate[`${iInfo}_zhu`] && (mode == "identity" || (mode == "guozhan" && _status.mode == "four"))) lib.translate[iInfo] = lib.translate[`${iInfo}_zhu`]; + else if (lib.translate[`${iInfo}_combat`] && get.is.versus()) lib.translate[iInfo] = lib.translate[`${iInfo}_combat`]; let deleteSkill = function (skill, iInfo) { let skillx = {}, info = get.info(skill); if (info) { - ["audio", "audioname", "audioname2"].forEach((name) => { + ["audio", "audioname", "audioname2"].forEach(name => { if (info[name]) skillx[name] = info[name]; }); } @@ -7592,11 +7156,7 @@ export class Game { if (lib.translate[iInfo]) lib.translate[iInfo] = "此模式下不可用"; if (lib.dynamicTranslate[skill]) lib.dynamicTranslate[skill] = () => "此模式下不可用"; }; - if ( - (info.forbid && info.forbid.includes(mode)) || - (info.mode && info.mode.includes(mode) == false) || - (info.available && info.available(mode) == false) - ) { + if ((info.forbid && info.forbid.includes(mode)) || (info.mode && info.mode.includes(mode) == false) || (info.available && info.available(mode) == false)) { deleteSkill(i, iInfo); return; } @@ -7613,30 +7173,24 @@ export class Game { const skill = info.ai, card = lib.card[info.viewAs.name].ai; if (card) - Object.keys(card).forEach((value) => { + Object.keys(card).forEach(value => { if (skill[value] == undefined) skill[value] = card[value]; else if (typeof skill[value] == "object") - Object.keys(card[value]).forEach((element) => { - if (skill[value][element] == undefined) - skill[value][element] = card[value][element]; + Object.keys(card[value]).forEach(element => { + if (skill[value][element] == undefined) skill[value][element] = card[value][element]; }); }); } if (info.inherit) { const skill = lib.skill[info.inherit]; if (skill) - Object.keys(skill).forEach((value) => { + Object.keys(skill).forEach(value => { if (info[value] != undefined) return; - if ( - value == "audio" && - (typeof info[value] == "number" || typeof info[value] == "boolean") - ) - info[value] = info.inherit; + if (value == "audio" && (typeof info[value] == "number" || typeof info[value] == "boolean")) info[value] = info.inherit; else info[value] = skill[value]; }); if (lib.translate[i] == undefined) lib.translate[i] = lib.translate[info.inherit]; - if (lib.translate[iInfo] == undefined) - lib.translate[iInfo] = lib.translate[`${info.inherit}_info`]; + if (lib.translate[iInfo] == undefined) lib.translate[iInfo] = lib.translate[`${info.inherit}_info`]; } if (info.limited) { if (info.mark === undefined) info.mark = true; @@ -7646,16 +7200,14 @@ export class Game { if (info.init === undefined) info.init = (player, skill) => (player.storage[skill] = false); } if (info.subSkill && !sub) - Object.keys(info.subSkill).forEach((value) => { + Object.keys(info.subSkill).forEach(value => { const iValue = `${i}_${value}`; lib.skill[iValue] = info.subSkill[value]; lib.skill[iValue].sub = true; if (info.subSkill[value].name) lib.translate[iValue] = info.subSkill[value].name; else lib.translate[iValue] = lib.translate[iValue] || lib.translate[i]; - if (info.subSkill[value].description) - lib.translate[`${iValue}_info`] = info.subSkill[value].description; - if (info.subSkill[value].marktext) - lib.translate[`${iValue}_bg`] = info.subSkill[value].marktext; + if (info.subSkill[value].description) lib.translate[`${iValue}_info`] = info.subSkill[value].description; + if (info.subSkill[value].marktext) lib.translate[`${iValue}_bg`] = info.subSkill[value].marktext; game.finishSkill(iValue, true); }); if (info.round) { @@ -7664,7 +7216,7 @@ export class Game { else if (Array.isArray(info.group)) info.group.add(k); else info.group = [k]; lib.skill[k] = ((round, name) => ({ - init: (player) => { + init: player => { if (typeof player.storage[name] !== "number") player.storage[name] = 1 - round; }, intro: { @@ -7684,12 +7236,7 @@ export class Game { popup: false, silent: true, content: () => { - if ( - lib.skill[event.name.slice(0, event.name.indexOf("_roundcount"))].round - - (game.roundNumber - player.storage[event.name]) > - 0 - ) - player.updateMarks(); + if (lib.skill[event.name.slice(0, event.name.indexOf("_roundcount"))].round - (game.roundNumber - player.storage[event.name]) > 0) player.updateMarks(); else player.unmarkSkill(event.name); }, }))(info.round, k); @@ -7741,24 +7288,18 @@ export class Game { return Math.max(0.1, equipValue - value); }, aiResultTarget = (player, target, card) => get.equipResult(player, target, card.name); - Object.keys(lib.card).forEach((libCardKey) => { + Object.keys(lib.card).forEach(libCardKey => { const info = `${libCardKey}_info`; if (lib.translate[`${info}_${mode}`]) lib.translate[info] = lib.translate[`${info}_${mode}`]; - else if ( - lib.translate[`${info}_zhu`] && - (mode == "identity" || (mode == "guozhan" && _status.mode == "four")) - ) - lib.translate[info] = lib.translate[`${info}_zhu`]; - else if (lib.translate[`${info}_combat`] && get.is.versus()) - lib.translate[info] = lib.translate[`${info}_combat`]; + else if (lib.translate[`${info}_zhu`] && (mode == "identity" || (mode == "guozhan" && _status.mode == "four"))) lib.translate[info] = lib.translate[`${info}_zhu`]; + else if (lib.translate[`${info}_combat`] && get.is.versus()) lib.translate[info] = lib.translate[`${info}_combat`]; const card = lib.card[libCardKey]; if (card.filterTarget && card.selectTarget == undefined) card.selectTarget = 1; if (card.autoViewAs) { if (!card.ai) card.ai = {}; if (!card.ai.order) { card.ai.order = lib.card[card.autoViewAs].ai.order; - if (!card.ai.order && lib.card[card.autoViewAs].ai.basic) - card.ai.order = lib.card[card.autoViewAs].ai.basic.order; + if (!card.ai.order && lib.card[card.autoViewAs].ai.basic) card.ai.order = lib.card[card.autoViewAs].ai.basic.order; } } if (card.type == "equip") { @@ -7794,7 +7335,7 @@ export class Game { if (card.allowMultiple == undefined) card.allowMultiple = false; } }); - Object.keys(lib.skill).forEach((value) => game.finishSkill(value)); + Object.keys(lib.skill).forEach(value => game.finishSkill(value)); } /** * 这玩意至少19种重载了吧 @@ -7815,7 +7356,7 @@ export class Game { skills.sort((a, b) => get.priority(a) - get.priority(b)); } const arg = argumentArray.slice(0, -2); - skills.forEach((value) => { + skills.forEach(value => { var mod = get.info(value).mod[name]; if (!mod) return; const result = mod.call(this, ...arg); @@ -7837,7 +7378,7 @@ export class Game { clearArena() { ui.control.innerHTML = ""; ui.arenalog.innerHTML = ""; - Array.from(ui.arena.childNodes).forEach((value) => { + Array.from(ui.arena.childNodes).forEach(value => { if (value == ui.canvas) return; if (value == ui.control) return; if (value == ui.arenalog) return; @@ -7882,7 +7423,7 @@ export class Game { delete ui.startServer; } if (ui.rooms) { - ui.rooms.forEach((value) => value.remove()); + ui.rooms.forEach(value => value.remove()); delete ui.rooms; } if (ui.roombase) { @@ -7911,16 +7452,12 @@ export class Game { ["g", "green"], ["b", "blue"], ]); - Array.from(arguments).forEach((value) => { + Array.from(arguments).forEach(value => { const itemtype = get.itemtype(value); if (itemtype == "player" || itemtype == "players") { str += `${get.translation(value)}`; str2 += get.translation(value); - } else if ( - itemtype == "cards" || - itemtype == "card" || - (typeof value == "object" && value && value.name) - ) { + } else if (itemtype == "cards" || itemtype == "card" || (typeof value == "object" && value && value.name)) { str += `${get.translation(value)}`; str2 += get.translation(value); } else if (typeof value == "object") { @@ -7934,9 +7471,7 @@ export class Game { str += `${get.translation(value)}`; str2 += get.translation(value); } else if (value[0] == "#") { - str += `${get.translation( - value.slice(2) - )}`; + str += `${get.translation(value.slice(2))}`; str2 += get.translation(value.slice(2)); } else { str += get.translation(value); @@ -7953,8 +7488,7 @@ export class Game { game.addVideo("log", null, lib.config.log_highlight ? str : str2); game.broadcast((str, str2) => game.log(lib.config.log_highlight ? str : str2), str, str2); if (!_status.video && !game.online) { - if (logvid) - game.logv(logvid, `
${lib.config.log_highlight ? str : str2}
`); + if (logvid) game.logv(logvid, `
${lib.config.log_highlight ? str : str2}
`); else logvid = _status.event.getLogv(); } if (lib.config.show_log == "off" || game.chess) return; @@ -7973,7 +7507,7 @@ export class Game { } if (!lib.config.clear_log) return; nodeentry.timeout = setTimeout(() => nodeentry.delete(), 1000); - Array.from(ui.arenalog.childNodes).forEach((value) => { + Array.from(ui.arenalog.childNodes).forEach(value => { if (!value.timeout) value.remove(); }); } @@ -7995,7 +7529,7 @@ export class Game { logvid = logvid || get.id(); game.broadcast(game.logv, player, card, targets, event, forced, logvid); if (typeof player == "string") { - const childNode = Array.from(ui.historybar.childNodes).find((value) => value.logvid == player); + const childNode = Array.from(ui.historybar.childNodes).find(value => value.logvid == player); if (childNode) childNode.added.push(card); return; } @@ -8042,8 +7576,7 @@ export class Game { node.cards = card[1].slice(0); card = card[0]; const info = [card.suit || "", card.number || "", card.name || "", card.nature || ""]; - if (!Array.isArray(node.cards) || !node.cards.length) - node.cards = [ui.create.card(node, "noclick", true).init(info)]; + if (!Array.isArray(node.cards) || !node.cards.length) node.cards = [ui.create.card(node, "noclick", true).init(info)]; if (card.name == "wuxie") { if (ui.historybar.firstChild && ui.historybar.firstChild.type == "wuxie") { ui.historybar.firstChild.players.push(player); @@ -8069,12 +7602,7 @@ export class Game { avatar.style.transform = ""; avatar.classList.add("avatar2"); node.appendChild(avatar); - if ( - targets && - targets.length == 1 && - targets[0] != player && - get.itemtype(targets[0]) == "player" - ) + if (targets && targets.length == 1 && targets[0] != player && get.itemtype(targets[0]) == "player") (() => { let avatar2; const target = targets[0]; @@ -8115,7 +7643,7 @@ export class Game { value.style.transform = `scale(1) translateY(${fullheight}px)`; value.removetimeout = setTimeout( ( - (current) => () => + current => () => current.remove() )(value), 500 @@ -8151,11 +7679,11 @@ export class Game { storeName, idbValidKey, value, - (event) => { + event => { if (typeof onSuccess == "function") onSuccess(event); resolve(event); }, - (event) => { + event => { if (typeof onError == "function") { onError(event); resolve(); @@ -8166,11 +7694,8 @@ export class Game { ); lib.status.reload++; return new Promise((resolve, reject) => { - const record = lib.db - .transaction([storeName], "readwrite") - .objectStore(storeName) - .put(value, idbValidKey); - record.onerror = (event) => { + const record = lib.db.transaction([storeName], "readwrite").objectStore(storeName).put(value, idbValidKey); + record.onerror = event => { if (typeof onError == "function") { onError(event); game.reload2(); @@ -8180,7 +7705,7 @@ export class Game { reject(event); } }; - record.onsuccess = (event) => { + record.onsuccess = event => { if (typeof onSuccess == "function") { _status.dburgent = true; onSuccess(event); @@ -8200,7 +7725,7 @@ export class Game { */ getDB(storeName, query, onSuccess, onError) { if (!lib.db) - return new Promise((resolve) => { + return new Promise(resolve => { if (typeof onSuccess == "function") onSuccess(null); resolve(null); }); @@ -8211,11 +7736,11 @@ export class Game { [ storeName, query, - (result) => { + result => { if (typeof onSuccess == "function") onSuccess(result); resolve(result); }, - (event) => { + event => { if (typeof onError == "function") { onError(event); resolve(); @@ -8228,11 +7753,8 @@ export class Game { query ? (resolve, reject) => { lib.status.reload++; - const idbRequest = lib.db - .transaction([storeName], "readwrite") - .objectStore(storeName) - .get(query); - idbRequest.onerror = (event) => { + const idbRequest = lib.db.transaction([storeName], "readwrite").objectStore(storeName).get(query); + idbRequest.onerror = event => { if (typeof onError == "function") { onError(event); game.reload2(); @@ -8242,7 +7764,7 @@ export class Game { reject(event); } }; - idbRequest.onsuccess = (event) => { + idbRequest.onsuccess = event => { const result = event.target.result; if (typeof onSuccess == "function") { _status.dburgent = true; @@ -8255,12 +7777,9 @@ export class Game { } : (resolve, reject) => { lib.status.reload++; - const idbRequest = lib.db - .transaction([storeName], "readwrite") - .objectStore(storeName) - .openCursor(), + const idbRequest = lib.db.transaction([storeName], "readwrite").objectStore(storeName).openCursor(), object = {}; - idbRequest.onerror = (event) => { + idbRequest.onerror = event => { if (typeof onError == "function") { onError(event); game.reload2(); @@ -8270,7 +7789,7 @@ export class Game { reject(event); } }; - idbRequest.onsuccess = (event) => { + idbRequest.onsuccess = event => { const result = event.target.result; if (result) { object[result.key] = result.value; @@ -8296,7 +7815,7 @@ export class Game { */ deleteDB(storeName, query, onSuccess, onError) { if (!lib.db) - return new Promise((resolve) => { + return new Promise(resolve => { if (typeof onSuccess == "function") onSuccess(false); resolve(false); }); @@ -8307,11 +7826,11 @@ export class Game { [ storeName, query, - (event) => { + event => { if (typeof onSuccess == "function") onSuccess(event); resolve(event); }, - (event) => { + event => { if (typeof onError == "function") { onError(event); resolve(); @@ -8323,11 +7842,8 @@ export class Game { return query ? new Promise((resolve, reject) => { lib.status.reload++; - const record = lib.db - .transaction([storeName], "readwrite") - .objectStore(storeName) - .delete(query); - record.onerror = (event) => { + const record = lib.db.transaction([storeName], "readwrite").objectStore(storeName).delete(query); + record.onerror = event => { if (typeof onError == "function") { onError(event); game.reload2(); @@ -8337,26 +7853,26 @@ export class Game { reject(event); } }; - record.onsuccess = (event) => { + record.onsuccess = event => { if (typeof onSuccess == "function") onSuccess(event); game.reload2(); resolve(event); }; }) - : game.getDB(storeName).then((object) => { + : game.getDB(storeName).then(object => { const keys = Object.keys(object); lib.status.reload += keys.length; const store = lib.db.transaction([storeName], "readwrite").objectStore(storeName); return Promise.allSettled( keys.map( - (key) => + key => new Promise((resolve, reject) => { const request = store.delete(key); - request.onerror = (event) => { + request.onerror = event => { game.reload2(); reject(event); }; - request.onsuccess = (event) => { + request.onsuccess = event => { game.reload2(); resolve(event); }; @@ -8384,7 +7900,7 @@ export class Game { lib.storage.version = lib.version; game.putDB("data", mode, lib.storage); } else - game.getDB("data", mode, (config) => { + game.getDB("data", mode, config => { if (!config) config = {}; if (value == undefined) delete config[key]; else config[key] = value; @@ -8422,16 +7938,16 @@ export class Game { let players = null, cards = null; if (lib.version != lib.config.version) - lib.changeLog.forEach((value) => { + lib.changeLog.forEach(value => { if (value.startsWith("players://")) try { - players = JSON.parse(value.slice(10)).filter((value) => lib.character[value]); + players = JSON.parse(value.slice(10)).filter(value => lib.character[value]); } catch (e) { players = null; } else if (value.startsWith("cards://")) try { - cards = JSON.parse(value.slice(8)).filter((value) => lib.card[value]); + cards = JSON.parse(value.slice(8)).filter(value => lib.card[value]); } catch (e) { cards = null; } @@ -8443,7 +7959,7 @@ export class Game { }); game.saveConfig("version", lib.version); if (_status.extensionChangeLog) - Object.keys(_status.extensionChangeLog).forEach((value) => { + Object.keys(_status.extensionChangeLog).forEach(value => { const li = document.createElement("li"); li.innerHTML = `${value}:${_status.extensionChangeLog[value]}`; ul.appendChild(li); @@ -8460,7 +7976,7 @@ export class Game { dialog.classList.add("withbg"); } if (cards && cards.length) { - dialog.addSmall([cards.map((value) => [get.translation(get.type(value)), "", value]), "vcard"]); + dialog.addSmall([cards.map(value => [get.translation(get.type(value)), "", value]), "vcard"]); dialog.classList.add("forcebutton"); dialog.classList.add("withbg"); } @@ -8559,8 +8075,8 @@ export class Game { clearModeConfig(mode) { if (_status.reloading) return; if (lib.db) { - game.getDB("config", null, (config) => - Object.keys(config).forEach((value) => { + game.getDB("config", null, config => + Object.keys(config).forEach(value => { if (value.substr(value.indexOf("_mode_config") + 13) == mode) game.saveConfig(value); }) ); @@ -8573,7 +8089,7 @@ export class Game { } catch (err) { config = {}; } - Object.keys(config).forEach((value) => { + Object.keys(config).forEach(value => { if (value.substr(value.indexOf("_mode_config") + 13) == mode) delete config[value]; }); localStorage.setItem(`${lib.configprefix}config`, JSON.stringify(config)); @@ -8585,13 +8101,11 @@ export class Game { * @param { string } [character2] */ addPlayer(position, character, character2) { - if (position < 0 || position > game.players.length + game.dead.length || position == undefined) - position = Math.ceil(Math.random() * (game.players.length + game.dead.length)); + if (position < 0 || position > game.players.length + game.dead.length || position == undefined) position = Math.ceil(Math.random() * (game.players.length + game.dead.length)); const players = game.players.concat(game.dead); ui.arena.setNumber(players.length + 1); - players.forEach((value) => { - if (parseInt(value.dataset.position) >= position) - value.dataset.position = parseInt(value.dataset.position) + 1; + players.forEach(value => { + if (parseInt(value.dataset.position) >= position) value.dataset.position = parseInt(value.dataset.position) + 1; }); const player = ui.create.player(ui.arena).addTempClass("start"); if (character) player.init(character, character2); @@ -8632,13 +8146,11 @@ export class Game { restorePlayer(player) { if (game.players.includes(player) || game.dead.includes(player)) return; let position = parseInt(player.dataset.position); - if (position < 0 || position > game.players.length + game.dead.length || position == undefined) - position = Math.ceil(Math.random() * (game.players.length + game.dead.length)); + if (position < 0 || position > game.players.length + game.dead.length || position == undefined) position = Math.ceil(Math.random() * (game.players.length + game.dead.length)); const players = game.players.concat(game.dead); ui.arena.setNumber(players.length + 1); - players.forEach((value) => { - if (parseInt(value.dataset.position) >= position) - value.dataset.position = parseInt(value.dataset.position) + 1; + players.forEach(value => { + if (parseInt(value.dataset.position) >= position) value.dataset.position = parseInt(value.dataset.position) + 1; }); game.players.push(player); delete player.removed; @@ -8652,16 +8164,14 @@ export class Game { * @param { Player } player */ removePlayer(player) { - if (_status.roundStart == player) - _status.roundStart = player.next || player.getNext() || game.players[0]; + if (_status.roundStart == player) _status.roundStart = player.next || player.getNext() || game.players[0]; const players = game.players.concat(game.dead); player.style.left = `${player.getLeft()}px`; player.style.top = `${player.getTop()}px`; if (player == undefined) player = game.dead[0] || game.me.next; const position = parseInt(player.dataset.position); - players.forEach((value) => { - if (parseInt(value.dataset.position) > position) - value.dataset.position = parseInt(value.dataset.position) - 1; + players.forEach(value => { + if (parseInt(value.dataset.position) > position) value.dataset.position = parseInt(value.dataset.position) - 1; }); if (player.isAlive()) { player.next.previous = player.previous; @@ -8722,7 +8232,7 @@ export class Game { enemyCount = 0; const rand = Math.random() < 0.5, sortCount = new Map(); - game.players.forEach((value) => { + game.players.forEach(value => { if (value.side == game.me.side) { if (rand) if (value == game.friendZhu) sortCount.set(value, -2); @@ -8765,7 +8275,7 @@ export class Game { filterSkills(skills, player, exclude) { const out = skills.slice().removeArray(Object.keys(player.disabledSkills)); if (!player.storage.skill_blocker || !player.storage.skill_blocker.length) return out; - return out.filter((value) => (exclude && exclude.includes(value)) || !get.is.blocked(value, player)); + return out.filter(value => (exclude && exclude.includes(value)) || !get.is.blocked(value, player)); } /** * @param { string[] } skills @@ -8776,9 +8286,7 @@ export class Game { const info = get.info(currentValue); if (info) { if (info.group) { - const adds = (Array.isArray(info.group) ? info.group : [info.group]).filter( - (i) => lib.skill[i] - ); + const adds = (Array.isArray(info.group) ? info.group : [info.group]).filter(i => lib.skill[i]); previousValue.push(...adds); } } else console.log(currentValue); @@ -8790,7 +8298,7 @@ export class Game { * @param { { [key:string]: any } } style */ css(style) { - return Object.keys(style).forEach((value) => { + return Object.keys(style).forEach(value => { let uiStyle = ui.style[value]; if (!uiStyle) { uiStyle = ui.style[value] = document.createElement("style"); @@ -8804,14 +8312,14 @@ export class Game { * @param { boolean } [includeOut] */ hasPlayer(func, includeOut) { - return game.players.some((value) => (includeOut || !value.isOut()) && func(value)); + return game.players.some(value => (includeOut || !value.isOut()) && func(value)); } /** * @param { (player: Player) => boolean } func * @param { boolean } [includeOut] */ hasPlayer2(func, includeOut) { - return game.players.concat(game.dead).some((value) => (includeOut || !value.isOut()) && func(value)); + return game.players.concat(game.dead).some(value => (includeOut || !value.isOut()) && func(value)); } /** * @param { (player: Player) => boolean } func @@ -8855,7 +8363,7 @@ export class Game { filterPlayer(func, list, includeOut) { if (!Array.isArray(list)) list = []; if (typeof func != "function") func = lib.filter.all; - return list.addArray(game.players.filter((value) => (includeOut || !value.isOut()) && func(value))); + return list.addArray(game.players.filter(value => (includeOut || !value.isOut()) && func(value))); } /** * @overload @@ -8871,33 +8379,28 @@ export class Game { filterPlayer2(func, list, includeOut) { if (!Array.isArray(list)) list = []; if (typeof func != "function") func = lib.filter.all; - return list.addArray( - game.players.concat(game.dead).filter((value) => (includeOut || !value.isOut()) && func(value)) - ); + return list.addArray(game.players.concat(game.dead).filter(value => (includeOut || !value.isOut()) && func(value))); } /** * @param { (player: Player) => boolean } func * @param { boolean } [includeOut] */ findPlayer(func, includeOut) { - return game.players.find((value) => (includeOut || !value.isOut()) && func(value)) || null; + return game.players.find(value => (includeOut || !value.isOut()) && func(value)) || null; } /** * @param { (player: Player) => boolean } func * @param { boolean } [includeOut] */ findPlayer2(func, includeOut) { - return ( - game.players.concat(game.dead).find((value) => (includeOut || !value.isOut()) && func(value)) || - null - ); + return game.players.concat(game.dead).find(value => (includeOut || !value.isOut()) && func(value)) || null; } /** * @param { (player: Player) => boolean } func * @param { boolean } [all] */ findCards(func, all) { - return Object.keys(lib.card).filter((value) => { + return Object.keys(lib.card).filter(value => { if (!lib.translate[`${value}_info`]) return false; if (lib.card[value].mode && lib.card[value].mode.includes(lib.config.mode) == false) return false; if (!all && !lib.inpile.includes(value)) return false; @@ -8906,7 +8409,7 @@ export class Game { } countGroup() { const list = lib.group.slice(0); - return game.countPlayer((current) => { + return game.countPlayer(current => { if (!list.includes(current.group)) return false; list.remove(current.group); return true; @@ -8946,7 +8449,7 @@ export let game = new Game(); /** * @param { InstanceType } [instance] */ -export let setGame = (instance) => { +export let setGame = instance => { game = instance || new Game(); if (lib.config.dev) { window.game = game;