diff --git a/.eslintrc.json b/.eslintrc.json index f0d2bdc86..fde84ce4b 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -2,16 +2,19 @@ "extends": "eslint:recommended", "env": { "browser": true, - "node": true, "es6": true, + "node": true, + "serviceworker": true, "worker": true }, "rules": { "no-console": 0, - "no-unused-vars": 0, - "no-undef": 0, - "no-redeclare": 0, - "require-yield": 0, + "no-constant-condition": [ + "error", + { + "checkLoops": false + } + ], "no-irregular-whitespace": [ "error", { @@ -19,13 +22,13 @@ "skipTemplates": true } ], - "no-constant-condition": [ - "error", - { - "checkLoops": false - } - ] /* , - "comma-dangle": ["error", "only-multiline"], - "complexity": ["error",100] */ + "no-redeclare": 0, + "no-undef": 0, + "no-unused-vars": 0, + "require-yield": 0 + }, + "parserOptions": { + "ecmaVersion": 13, + "sourceType": "module" } } \ No newline at end of file diff --git a/.gitignore b/.gitignore index 576ce9437..41a5761d6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,25 @@ +!extension/boss +!extension/cardpile +!extension/coin +!extension/wuxing +!node_modules/options +!node_modules/ultron +!node_modules/ws +._* .DS_Store .DS_Store? -._* +.idea .Spotlight-V100 .Trashes -ehthumbs.db -Thumbs.db -localStorage.json .vscode -.idea +app +app.html +ehthumbs.db +extension +jsconfig.json +localStorage.json +main.js +node_modules +noname.ico +package.json +Thumbs.db diff --git a/noname.js b/noname.js new file mode 100644 index 000000000..517b9e043 --- /dev/null +++ b/noname.js @@ -0,0 +1,4 @@ +export * from "./noname/ai.js"; +export * from "./noname/status.js"; +export * from "./noname/library.js"; +export * from "./noname/get.js"; diff --git a/noname/ai.js b/noname/ai.js new file mode 100644 index 000000000..67ad92185 --- /dev/null +++ b/noname/ai.js @@ -0,0 +1,7 @@ +import { Get } from "../noname.js"; +import { BasicAI } from "./ai/basic.js"; + +export const ai = { + basic: BasicAI, + get: Get +}; diff --git a/noname/ai/basic.js b/noname/ai/basic.js new file mode 100644 index 000000000..ac6e2569e --- /dev/null +++ b/noname/ai/basic.js @@ -0,0 +1,180 @@ +import { status as _status } from "../../noname.js"; + +export class BasicAI { + static chooseButton(check) { + var event = _status.event; + var i, j, range, buttons, buttons2; + var ok = false, forced = event.forced; + var iwhile = 100; + while (iwhile--) { + range = get.select(event.selectButton); + if (ui.selected.buttons.length >= range[0]) { + ok = true; + } + if (range[1] <= -1) { + j = 0; + for (i = 0; i < ui.selected.buttons.length; i++) { + j += check(ui.selected.buttons[i]); + } + return (j > 0); + } + buttons = get.selectableButtons(); + if (buttons.length == 0) { + return ok; + } + buttons2 = buttons.slice(0); + var ix = 0; + var checkix = check(buttons[0], buttons2); + for (i = 1; i < buttons.length; i++) { + var checkixtmp = check(buttons[i], buttons2); + if (checkixtmp > checkix) { + ix = i; + checkix = checkixtmp; + } + } + // buttons.sort(function(a,b){ + // return check(b,buttons2)-check(a,buttons2); + // }); + if (check(buttons[ix]) <= 0) { + if (!forced || ok) { + return ok; + } + } + buttons[ix].classList.add('selected'); + ui.selected.buttons.add(buttons[ix]); + game.check(); + if (ui.selected.buttons.length >= range[0]) { + ok = true; + } + if (ui.selected.buttons.length == range[1]) { + return true; + } + } + } + static chooseCard(check) { + var event = _status.event; + if (event.filterCard == undefined) return (check() > 0); + var i, j, range, cards, cards2, skills, check, effect; + var ok = false, forced = event.forced; + var iwhile = 100; + while (iwhile--) { + range = get.select(event.selectCard); + if (ui.selected.cards.length >= range[0]) { + ok = true; + } + if (range[1] <= -1) { + if (ui.selected.cards.length == 0) return true; + j = 0; + for (i = 0; i < ui.selected.cards.length; i++) { + effect = check(ui.selected.cards[i]); + if (effect < 0) j -= Math.sqrt(-effect); + else j += Math.sqrt(effect); + } + return (j > 0); + } + cards = get.selectableCards(); + if (!_status.event.player._noSkill) { + cards = cards.concat(get.skills()); + } + if (cards.length == 0) { + return ok; + } + cards2 = cards.slice(0); + // cards.sort(function(a,b){ + // return (check(b,cards2)-check(a,cards2)); + // }); + var ix = 0; + var checkix = check(cards[0], cards2); + for (i = 1; i < cards.length; i++) { + var checkixtmp = check(cards[i], cards2); + if (checkixtmp > checkix) { + ix = i; + checkix = checkixtmp; + } + } + if (check(cards[ix]) <= 0) { + if (!forced || ok) { + return ok; + } + } + if (typeof cards[ix] == 'string') { + ui.click.skill(cards[ix]); + var info = get.info(event.skill); + if (info.filterCard) { + check = info.check || get.unuseful2; + return (ai.basic.chooseCard(check)); + } + else { + return true; + } + } + else { + cards[ix].classList.add('selected'); + ui.selected.cards.add(cards[ix]); + game.check(); + if (ui.selected.cards.length >= range[0]) { + ok = true; + } + if (ui.selected.cards.length == range[1]) { + return true; + } + } + } + } + static chooseTarget(check) { + var event = _status.event; + if (event.filterTarget == undefined) return (check() > 0); + var i, j, range, targets, targets2, effect; + var ok = false, forced = event.forced; + var iwhile = 100; + while (iwhile--) { + range = get.select(event.selectTarget); + if (ui.selected.targets.length >= range[0]) { + ok = true; + } + if (range[1] <= -1) { + j = 0; + for (i = 0; i < ui.selected.targets.length; i++) { + effect = check(ui.selected.targets[i]); + if (effect < 0) j -= Math.sqrt(-effect); + else j += Math.sqrt(effect); + } + return (j > 0); + } + else if (range[1] == 0) { + return check() > 0 + } + targets = get.selectableTargets(); + if (targets.length == 0) { + return range[0] == 0 || ok; + } + targets2 = targets.slice(0); + // targets.sort(function(a,b){ + // return check(b)-check(a); + // }); + var ix = 0; + var checkix = check(targets[0], targets2); + for (i = 1; i < targets.length; i++) { + var checkixtmp = check(targets[i], targets2); + if (checkixtmp > checkix) { + ix = i; + checkix = checkixtmp; + } + } + if (check(targets[ix]) <= 0) { + if (!forced || ok) { + return ok; + } + } + targets[ix].classList.add('selected'); + ui.selected.targets.add(targets[ix]); + game.check(); + if (ui.selected.targets.length >= range[0]) { + ok = true; + } + if (ui.selected.targets.length == range[1]) { + return true; + } + } + } +} diff --git a/noname/get.js b/noname/get.js new file mode 100644 index 000000000..a4645e9dd --- /dev/null +++ b/noname/get.js @@ -0,0 +1,17 @@ +import { Library as lib, status as _status } from "../noname.js"; + +export class Get { + /** + * @template T + * @overload + * @param {T} key + * @returns {typeof _status.event[T]} + */ + /** + * @overload + * @returns {typeof _status.event} + */ + static event(key) { + return key ? _status.event[key] : _status.event; + } +} diff --git a/noname/library.js b/noname/library.js new file mode 100644 index 000000000..5776826ec --- /dev/null +++ b/noname/library.js @@ -0,0 +1,69 @@ +import { animate } from "./library/animate.js"; +import { cardPack } from "./library/card-pack.js"; +import { cardType } from "./library/card-type.js"; +import { characterFilter } from "./library/character-filter.js"; +import { characterIntro } from "./library/character-intro.js"; +import { characterPack } from "./library/character-pack.js"; +import { characterReplace } from "./library/character-replace.js"; +import { characterSort } from "./library/character-sort.js"; +import { characterTitle } from "./library/character-title.js"; +import { dynamicTranslate } from "./library/dynamic-translate.js"; +import { element } from "./library/element.js"; +import { emotionList } from "./library/emotion-list.js"; +import { extensionPack } from "./library/extension-pack.js"; +import { skin } from "./library/skin.js"; +import { updateURLs } from "./library/update-urls.js"; + +const nonameInitialized = localStorage.getItem('noname_inited'); + +export class Library { + static configprefix = "noname_0.9_"; + static versionOL = 27; + static updateURLS = updateURLs; + static updateURL = updateURLs.github; + static mirrorURL = updateURLs.coding; + static hallURL = "47.99.105.222"; + static assetURL = typeof nonameInitialized != 'string' || nonameInitialized == 'nodejs' ? '' : nonameInitialized; + static userAgent = navigator.userAgent.toLowerCase(); + static compatibleEdition = Boolean(typeof nonameInitialized == 'string' && nonameInitialized.match(/\/(?:com\.widget|yuri\.nakamura)\.noname\//)); + static changeLog = []; + static updates = []; + static canvasUpdates = []; + static video = []; + static skilllist = []; + static connectBanned = []; + static characterIntro = characterIntro; + static characterTitle = characterTitle; + static characterPack = characterPack; + static characterFilter = characterFilter; + static characterSort = characterSort; + static characterReplace = characterReplace; + static characterGuozhanFilter = ["mode_guozhan"]; + static dynamicTranslate = dynamicTranslate; + static cardPack = cardPack; + static skin = skin; + static onresize = []; + static onphase = []; + static onwash = []; + static onover = []; + static ondb = []; + static ondb2 = []; + static chatHistory = []; + static emotionList = emotionList; + static animate = animate; + static onload = []; + static onload2 = []; + static onprepare = []; + static arenaReady = []; + static onfree = []; + static inpile = []; + static inpile_nature = []; + static extensions = []; + static extensionPack = extensionPack; + static cardType = cardType; + static element = element; + + constructor() { + throw new TypeError(`${new.target.name} is not a constructor`); + } +} diff --git a/noname/library/animate.js b/noname/library/animate.js new file mode 100644 index 000000000..cace6e142 --- /dev/null +++ b/noname/library/animate.js @@ -0,0 +1,7 @@ +import { animateCard } from "./animate/card.js"; +import { animateSkill } from "./animate/skill.js"; + +export const animate = { + skill: animateSkill, + card: animateCard +}; diff --git a/noname/library/animate/card.d.ts b/noname/library/animate/card.d.ts new file mode 100644 index 000000000..5534c58dd --- /dev/null +++ b/noname/library/animate/card.d.ts @@ -0,0 +1,3 @@ +interface AnimateCard extends Record { } + +export const animateCard: AnimateCard; diff --git a/noname/library/animate/card.js b/noname/library/animate/card.js new file mode 100644 index 000000000..57b8ce511 --- /dev/null +++ b/noname/library/animate/card.js @@ -0,0 +1 @@ +export const animateCard = {}; diff --git a/noname/library/animate/skill.d.ts b/noname/library/animate/skill.d.ts new file mode 100644 index 000000000..d4bd33ef5 --- /dev/null +++ b/noname/library/animate/skill.d.ts @@ -0,0 +1,3 @@ +interface AnimateSkill extends Record { } + +export const animateSkill: AnimateSkill; diff --git a/noname/library/animate/skill.js b/noname/library/animate/skill.js new file mode 100644 index 000000000..316153f39 --- /dev/null +++ b/noname/library/animate/skill.js @@ -0,0 +1 @@ +export const animateSkill = {}; diff --git a/noname/library/card-pack.d.ts b/noname/library/card-pack.d.ts new file mode 100644 index 000000000..069481296 --- /dev/null +++ b/noname/library/card-pack.d.ts @@ -0,0 +1,3 @@ +interface CardPack extends Record { } + +export const cardPack: CardPack; diff --git a/noname/library/card-pack.js b/noname/library/card-pack.js new file mode 100644 index 000000000..1ca34c63a --- /dev/null +++ b/noname/library/card-pack.js @@ -0,0 +1 @@ +export const cardPack = {}; diff --git a/noname/library/card-type.d.ts b/noname/library/card-type.d.ts new file mode 100644 index 000000000..9c383d7a6 --- /dev/null +++ b/noname/library/card-type.d.ts @@ -0,0 +1,3 @@ +interface CardType extends Record { } + +export const cardType: CardType; diff --git a/noname/library/card-type.js b/noname/library/card-type.js new file mode 100644 index 000000000..b38a1eb64 --- /dev/null +++ b/noname/library/card-type.js @@ -0,0 +1 @@ +export const cardType = {}; diff --git a/noname/library/character-filter.d.ts b/noname/library/character-filter.d.ts new file mode 100644 index 000000000..63f38953a --- /dev/null +++ b/noname/library/character-filter.d.ts @@ -0,0 +1,3 @@ +interface CharacterFilter extends Record boolean> { } + +export const characterFilter: CharacterFilter; diff --git a/noname/library/character-filter.js b/noname/library/character-filter.js new file mode 100644 index 000000000..c83393b66 --- /dev/null +++ b/noname/library/character-filter.js @@ -0,0 +1 @@ +export const characterFilter = {}; diff --git a/noname/library/character-information.ts b/noname/library/character-information.ts new file mode 100644 index 000000000..5457cce90 --- /dev/null +++ b/noname/library/character-information.ts @@ -0,0 +1,4 @@ +type CharacterSex = "double" | "female" | "male" | "none" | "unknown" | string & {}; +type CharacterGroup = "wei" | "shu" | "wu" | "qun" | "jin"; +type CharacterHP = number | `${number}/${number}` | `${number}/${number}/${number}`; +export type CharacterInformation = [CharacterSex, CharacterGroup, CharacterHP, string[], string[]?]; diff --git a/noname/library/character-intro.d.ts b/noname/library/character-intro.d.ts new file mode 100644 index 000000000..1bb84d5b6 --- /dev/null +++ b/noname/library/character-intro.d.ts @@ -0,0 +1,3 @@ +interface CharacterIntro extends Record { } + +export const characterIntro: CharacterIntro; diff --git a/noname/library/character-intro.js b/noname/library/character-intro.js new file mode 100644 index 000000000..5e82988b8 --- /dev/null +++ b/noname/library/character-intro.js @@ -0,0 +1 @@ +export const characterIntro = {}; diff --git a/noname/library/character-pack.d.ts b/noname/library/character-pack.d.ts new file mode 100644 index 000000000..9ee07cc77 --- /dev/null +++ b/noname/library/character-pack.d.ts @@ -0,0 +1,5 @@ +import { CharacterInformation } from "./character-information"; + +interface CharacterPack extends Record> { } + +export const characterPack: CharacterPack; diff --git a/noname/library/character-pack.js b/noname/library/character-pack.js new file mode 100644 index 000000000..5c62945fc --- /dev/null +++ b/noname/library/character-pack.js @@ -0,0 +1 @@ +export const characterPack = {}; diff --git a/noname/library/character-replace.d.ts b/noname/library/character-replace.d.ts new file mode 100644 index 000000000..56f2742f6 --- /dev/null +++ b/noname/library/character-replace.d.ts @@ -0,0 +1,3 @@ +interface CharacterReplace extends Record { } + +export const characterReplace: CharacterReplace; diff --git a/noname/library/character-replace.js b/noname/library/character-replace.js new file mode 100644 index 000000000..0b94a222e --- /dev/null +++ b/noname/library/character-replace.js @@ -0,0 +1 @@ +export const characterReplace = {}; diff --git a/noname/library/character-sort.d.ts b/noname/library/character-sort.d.ts new file mode 100644 index 000000000..c2771a0cc --- /dev/null +++ b/noname/library/character-sort.d.ts @@ -0,0 +1,3 @@ +interface CharacterSort extends Record> { } + +export const characterSort: CharacterSort; diff --git a/noname/library/character-sort.js b/noname/library/character-sort.js new file mode 100644 index 000000000..4728ab53a --- /dev/null +++ b/noname/library/character-sort.js @@ -0,0 +1 @@ +export const characterSort = {}; diff --git a/noname/library/character-title.d.ts b/noname/library/character-title.d.ts new file mode 100644 index 000000000..54e55a647 --- /dev/null +++ b/noname/library/character-title.d.ts @@ -0,0 +1,3 @@ +interface CharacterTitle extends Record { } + +export const characterTitle: CharacterTitle; diff --git a/noname/library/character-title.js b/noname/library/character-title.js new file mode 100644 index 000000000..12e7faed4 --- /dev/null +++ b/noname/library/character-title.js @@ -0,0 +1 @@ +export const characterTitle = {}; diff --git a/noname/library/dynamic-translate.d.ts b/noname/library/dynamic-translate.d.ts new file mode 100644 index 000000000..a04a11534 --- /dev/null +++ b/noname/library/dynamic-translate.d.ts @@ -0,0 +1,5 @@ +import { Player } from "./element/player"; + +interface DynamicTranslate extends Record string> { } + +export const dynamicTranslate: DynamicTranslate; diff --git a/noname/library/dynamic-translate.js b/noname/library/dynamic-translate.js new file mode 100644 index 000000000..d4ef217a6 --- /dev/null +++ b/noname/library/dynamic-translate.js @@ -0,0 +1 @@ +export const dynamicTranslate = {}; diff --git a/noname/library/element.js b/noname/library/element.js new file mode 100644 index 000000000..f14913cbf --- /dev/null +++ b/noname/library/element.js @@ -0,0 +1,7 @@ +import { GameEvent } from "./element/game-event.js"; +import { Player } from "./element/player.js"; + +export const element = { + Player: Player, + GameEvent: GameEvent +}; diff --git a/noname/library/element/game-event.js b/noname/library/element/game-event.js new file mode 100644 index 000000000..e13272baa --- /dev/null +++ b/noname/library/element/game-event.js @@ -0,0 +1,50 @@ +import { Get as get } from "../../../noname.js"; + +export class GameEvent { + /** + * @param {string} [name] + * @param {false} [trigger] + */ + constructor(name, trigger) { + if (typeof name == 'string') { + this.name = name; + const gameEvent = get.event(); + + if (gameEvent) { + const type = `onNext${name[0].toUpperCase()}${name.slice(1)}`; + if (gameEvent.hasHandler(type)) this.pushHandler(...gameEvent.getHandler(type)); + } + + game.globalEventHandlers.addHandlerToEvent(this); + } + + this.step = 0; + this.finished = false; + /** + * @type {GameEvent[]} + */ + this.next = []; + /** + * @type {GameEvent[]} + */ + this.after = []; + this.custom = { + add: {}, + replace: {} + }; + this._aiexclude = []; + this._notrigger = []; + this._result = {}; + this._set = []; + if (trigger !== false && !game.online) this._triggered = 0; + } + + static initialGameEvent() { + return (new this).finish(); + } + + finish() { + this.finished = true; + return this; + } +} diff --git a/noname/library/element/player.js b/noname/library/element/player.js new file mode 100644 index 000000000..c5810f777 --- /dev/null +++ b/noname/library/element/player.js @@ -0,0 +1 @@ +export class Player { } diff --git a/noname/library/emotion-list.d.ts b/noname/library/emotion-list.d.ts new file mode 100644 index 000000000..1bfe44410 --- /dev/null +++ b/noname/library/emotion-list.d.ts @@ -0,0 +1,3 @@ +interface EmotionList extends Record { } + +export const emotionList: EmotionList; diff --git a/noname/library/emotion-list.js b/noname/library/emotion-list.js new file mode 100644 index 000000000..cc82d5f14 --- /dev/null +++ b/noname/library/emotion-list.js @@ -0,0 +1,10 @@ +export const emotionList = { + xiaowu_emotion: 14, + xiaokuo_emotion: 8, + shibing_emotion: 15, + guojia_emotion: 20, + zhenji_emotion: 20, + xiaosha_emotion: 20, + xiaotao_emotion: 20, + xiaojiu_emotion: 20 +}; diff --git a/noname/library/extension-pack.js b/noname/library/extension-pack.js new file mode 100644 index 000000000..b712adc52 --- /dev/null +++ b/noname/library/extension-pack.js @@ -0,0 +1 @@ +export const extensionPack = {}; diff --git a/noname/library/skin.d.ts b/noname/library/skin.d.ts new file mode 100644 index 000000000..58e09182c --- /dev/null +++ b/noname/library/skin.d.ts @@ -0,0 +1,3 @@ +interface Skin extends Record { } + +export const skin: Skin; diff --git a/noname/library/skin.js b/noname/library/skin.js new file mode 100644 index 000000000..62b959fb8 --- /dev/null +++ b/noname/library/skin.js @@ -0,0 +1 @@ +export const skin = {}; diff --git a/noname/library/update-urls.d.ts b/noname/library/update-urls.d.ts new file mode 100644 index 000000000..57c2799ae --- /dev/null +++ b/noname/library/update-urls.d.ts @@ -0,0 +1,3 @@ +interface UpdateURLs extends Record { } + +export const updateURLs: UpdateURLs; diff --git a/noname/library/update-urls.js b/noname/library/update-urls.js new file mode 100644 index 000000000..e69287285 --- /dev/null +++ b/noname/library/update-urls.js @@ -0,0 +1,4 @@ +export const updateURLs = { + coding: "https://gitcode.net/sinat_33405273/noname/-/raw/", + github: "https://raw.githubusercontent.com/libccy/noname" +}; diff --git a/noname/status.js b/noname/status.js new file mode 100644 index 000000000..d91bb53d0 --- /dev/null +++ b/noname/status.js @@ -0,0 +1,34 @@ +import { Library as lib } from "../noname.js"; +import { aiStatus } from "./status/ai.js"; +import { cardTag } from "./status/card-tag.js"; +import { postReconnect } from "./status/post-reconnect.js"; + +export const status = { + paused: false, + paused2: false, + paused3: false, + over: false, + clicked: false, + auto: false, + event: lib.element.GameEvent.initialGameEvent(), + ai: aiStatus, + lastdragchange: [], + skillaudio: [], + dieClose: [], + dragline: [], + dying: [], + /** + * @type {import("./status/global-history.js").GlobalHistory[]} + */ + globalHistory: [{ + cardMove: [], + custom: [], + useCard: [], + changeHp: [], + everything: [] + }], + cardtag: cardTag, + renku: [], + prehidden_skills: [], + postReconnect: postReconnect +} diff --git a/noname/status/ai.d.ts b/noname/status/ai.d.ts new file mode 100644 index 000000000..2e5307f7b --- /dev/null +++ b/noname/status/ai.d.ts @@ -0,0 +1,7 @@ +import { Player } from "../library/element/player"; + +interface AIStatus extends Record { + customAttitude: ((from: Player, to: Player) => number)[]; +} + +export const aiStatus: AIStatus; diff --git a/noname/status/ai.js b/noname/status/ai.js new file mode 100644 index 000000000..1c105a077 --- /dev/null +++ b/noname/status/ai.js @@ -0,0 +1,3 @@ +export const aiStatus = { + customAttitude: [] +}; diff --git a/noname/status/card-tag.d.ts b/noname/status/card-tag.d.ts new file mode 100644 index 000000000..59b4fdce0 --- /dev/null +++ b/noname/status/card-tag.d.ts @@ -0,0 +1,3 @@ +interface CardTag extends Record { } + +export const cardTag: CardTag; diff --git a/noname/status/card-tag.js b/noname/status/card-tag.js new file mode 100644 index 000000000..6006ca59e --- /dev/null +++ b/noname/status/card-tag.js @@ -0,0 +1,7 @@ +export const cardTag = { + yingbian_zhuzhan: [], + yingbian_kongchao: [], + yingbian_fujia: [], + yingbian_canqu: [], + yingbian_force: [] +}; diff --git a/noname/status/global-history.d.ts b/noname/status/global-history.d.ts new file mode 100644 index 000000000..79347d87e --- /dev/null +++ b/noname/status/global-history.d.ts @@ -0,0 +1,9 @@ +import { GameEvent } from "../library/element/game-event"; + +export interface GlobalHistory { + cardMove: GameEvent[]; + custom: any[]; + useCard: GameEvent[]; + changeHp: GameEvent[]; + everything: GameEvent[]; +} diff --git a/noname/status/post-reconnect.js b/noname/status/post-reconnect.js new file mode 100644 index 000000000..81d5bfa86 --- /dev/null +++ b/noname/status/post-reconnect.js @@ -0,0 +1 @@ +export const postReconnect = {};