Merge pull request #1225 from nofficalfs/Dev-Pref-Another

对代码样式规范的一些细节整理
This commit is contained in:
Spmario233 2024-04-18 14:31:39 +08:00 committed by GitHub
commit b52094ad2e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 292 additions and 181 deletions

View File

@ -31,4 +31,4 @@
"ecmaVersion": 13,
"sourceType": "module"
}
}
}

View File

@ -32,4 +32,4 @@
- [ ] 如果此次PR需要扩展跟进我已在`扩展适配`中写入详细文档
- [ ] 如果这个PR解决了一个issue我在`诱因和背景`中明确链接到该issue
- [ ] 我保证该PR中没有随意修改换行符等内容没有制造出大量的Diff
- [ ] 我保证该PR遵循项目中`.editorconfig`、`.eslintrc.json`和`.prettierrc`所规定的代码样式,并且已经通过`prettier`格式化过代码
- [ ] 我保证该PR遵循项目中`.editorconfig`、`eslint.config.mjs`和`prettier.config.mjs`所规定的代码样式,并且已经通过`prettier`格式化过代码

1
.gitignore vendored
View File

@ -30,3 +30,4 @@ noname.ico
package-lock.json
package.json
Thumbs.db
bun.lockb

View File

@ -1,12 +0,0 @@
{
"arrowParens": "always",
"bracketSpacing": true,
"endOfLine": "lf",
"printWidth": 110,
"proseWrap": "preserve",
"quoteProps": "as-needed",
"semi": true,
"tabWidth": 4,
"trailingComma": "es5",
"useTabs": true
}

View File

@ -1,6 +1,6 @@
window.noname_character_rank = {
s: [
'sp_sunce',
"sp_sunce",
"gjqt_bailitusu",
"gjqt_beiluo",
"gjqt_xieyi",
@ -1720,7 +1720,7 @@ window.noname_character_rank = {
],
rarity: {
legend: [
'sp_sunce',
"sp_sunce",
"star_caoren",
"dc_zhaoyun",
"dc_caocao",

View File

@ -143,7 +143,7 @@ game.import("character", function () {
"sp_zhangliao",
"sp_ol_zhanghe",
"sp_menghuo",
'sp_sunce',
"sp_sunce",
],
sp_qifu: [
"ol_feiyi",
@ -184,12 +184,12 @@ game.import("character", function () {
ol_mengda(mode) {
return mode !== "guozhan";
},
ol_mengda(mode){
return mode!=='guozhan';
ol_mengda(mode) {
return mode !== "guozhan";
},
},
character: {
sp_sunce:['male','qun',4,['olliantao']],
sp_sunce: ["male", "qun", 4, ["olliantao"]],
ol_liupi: ["male", "qun", 4, ["olyicheng"]],
ol_lukai: ["male", "wu", 3, ["olxuanzhu", "oljiane"]],
liupan: ["male", "qun", 4, ["olpijing"]],
@ -968,117 +968,177 @@ game.import("character", function () {
},
skill: {
//SP孙策
olliantao:{
audio:2,
trigger:{player:'phaseUseBegin'},
filter(event,player){
return game.hasPlayer(target=>target!=player);
olliantao: {
audio: 2,
trigger: { player: "phaseUseBegin" },
filter(event, player) {
return game.hasPlayer((target) => target != player);
},
async cost(event,trigger,player){
event.result=await player.chooseTarget(get.prompt2('olliantao'),lib.filter.notMe).set('ai',target=>{
const player=get.event('player'),att=get.attitude(player,target);
const colors=Object.keys(lib.color).filter(i=>i!='none');
if(!colors.some(color=>player.hasCard(card=>{
const juedou=get.autoViewAs({name:'juedou'},[card]);
return player.canUse(juedou,target,false);
},'h'))) return 20+(3-get.sgn(att))+Math.random();
const effs=colors.reduce((list,color)=>{
const cards=player.getCards('h',card=>{
const juedou=get.autoViewAs({name:'juedou'},[card]);
return player.canUse(juedou,target,false);
});
if(cards.length){
list.push(cards.reduce((sum,card)=>{
const juedou=get.autoViewAs({name:'juedou'},[card]);
return sum+get.effect(target,card,player,player);
},0));
}
return list;
},[]);
return Math[att>0?'max':'min'].apply(Math,list);
}).forResult();
async cost(event, trigger, player) {
event.result = await player
.chooseTarget(get.prompt2("olliantao"), lib.filter.notMe)
.set("ai", (target) => {
const player = get.event("player"),
att = get.attitude(player, target);
const colors = Object.keys(lib.color).filter((i) => i != "none");
if (
!colors.some((color) =>
player.hasCard((card) => {
const juedou = get.autoViewAs({ name: "juedou" }, [card]);
return player.canUse(juedou, target, false);
}, "h")
)
)
return 20 + (3 - get.sgn(att)) + Math.random();
const effs = colors.reduce((list, color) => {
const cards = player.getCards("h", (card) => {
const juedou = get.autoViewAs({ name: "juedou" }, [card]);
return player.canUse(juedou, target, false);
});
if (cards.length) {
list.push(
cards.reduce((sum, card) => {
const juedou = get.autoViewAs({ name: "juedou" }, [card]);
return sum + get.effect(target, card, player, player);
}, 0)
);
}
return list;
}, []);
return Math[att > 0 ? "max" : "min"].apply(Math, list);
})
.forResult();
},
async content(event,trigger,player){
const target=event.targets[0];
const colors=Object.keys(lib.color).filter(i=>i!='none');
if(colors.length&&player.countCards('h')){
const result=await target.chooseControl(colors)
.set('prompt','连讨:请选择一个颜色').set('ai',()=>{
const player=get.event('player'),source=get.event().getParent().player;
let controls=get.event('controls').slice();
if(controls.length==1) return controls[0];
const getSum=function(color,player,source){
return source.getCards('h',card=>{
if(get.color(card)!=color) return false;
const juedou=get.autoViewAs({name:'juedou'},[card]);
return source.canUse(juedou,player,false);
}).reduce((num,card)=>{
const juedou=get.autoViewAs({name:'juedou'},[card]);
return num+get.effect(player,card,source,player);
},0);
};
return controls.sort((a,b)=>getSum(b,player,source)-getSum(a,player,source))[0];
}).set('prompt2',get.translation(player)+'将对你依次使用由其手牌中所有此颜色的牌转化的【决斗】').forResult();
const color=result.control;
game.broadcastAll((color,target)=>{
lib.skill.olliantao_backup.filterCardx=[color,target];
lib.skill.olliantao_backup.filterCard=function(card,player){
const list=lib.skill.olliantao_backup.filterCardx;
if(get.color(card)!=list[0]) return false;
const juedou=get.autoViewAs({name:'juedou'},[card]);
return player.canUse(juedou,list[1],false);
};
},color,target);
while(target.isIn()&&player.hasCard(card=>lib.skill.olliantao_backup.filterCard(card,player))&&!game.getGlobalHistory('everything',evt=>{
return evt.name=='dying'&&[player,target].includes(evt.player)&&evt.getParent('olliantao')==event;
}).length){
await player.chooseToUse().set('forced',true)
.set('openskilldialog','连讨:将一张'+get.translation(color)+'手牌当作【决斗】对'+get.translation(target)+'使用')
.set('norestore',true).set('_backupevent','olliantao_backup').set('custom',{
add:{},
replace:{window:function(){}},
}).backup('olliantao_backup').set('targetRequired',true).set('complexSelect',true)
.set('filterTarget',function(card,player,target){
if(target!=_status.event.sourcex&&!ui.selected.targets.includes(_status.event.sourcex)) return false;
return lib.filter.targetEnabled.apply(this, arguments);
}).set('sourcex',target).set('addCount',false);
async content(event, trigger, player) {
const target = event.targets[0];
const colors = Object.keys(lib.color).filter((i) => i != "none");
if (colors.length && player.countCards("h")) {
const result = await target
.chooseControl(colors)
.set("prompt", "连讨:请选择一个颜色")
.set("ai", () => {
const player = get.event("player"),
source = get.event().getParent().player;
let controls = get.event("controls").slice();
if (controls.length == 1) return controls[0];
const getSum = function (color, player, source) {
return source
.getCards("h", (card) => {
if (get.color(card) != color) return false;
const juedou = get.autoViewAs({ name: "juedou" }, [card]);
return source.canUse(juedou, player, false);
})
.reduce((num, card) => {
const juedou = get.autoViewAs({ name: "juedou" }, [card]);
return num + get.effect(player, card, source, player);
}, 0);
};
return controls.sort(
(a, b) => getSum(b, player, source) - getSum(a, player, source)
)[0];
})
.set(
"prompt2",
get.translation(player) +
"将对你依次使用由其手牌中所有此颜色的牌转化的【决斗】"
)
.forResult();
const color = result.control;
game.broadcastAll(
(color, target) => {
lib.skill.olliantao_backup.filterCardx = [color, target];
lib.skill.olliantao_backup.filterCard = function (card, player) {
const list = lib.skill.olliantao_backup.filterCardx;
if (get.color(card) != list[0]) return false;
const juedou = get.autoViewAs({ name: "juedou" }, [card]);
return player.canUse(juedou, list[1], false);
};
},
color,
target
);
while (
target.isIn() &&
player.hasCard((card) => lib.skill.olliantao_backup.filterCard(card, player)) &&
!game.getGlobalHistory("everything", (evt) => {
return (
evt.name == "dying" &&
[player, target].includes(evt.player) &&
evt.getParent("olliantao") == event
);
}).length
) {
await player
.chooseToUse()
.set("forced", true)
.set(
"openskilldialog",
"连讨:将一张" +
get.translation(color) +
"手牌当作【决斗】对" +
get.translation(target) +
"使用"
)
.set("norestore", true)
.set("_backupevent", "olliantao_backup")
.set("custom", {
add: {},
replace: { window: function () {} },
})
.backup("olliantao_backup")
.set("targetRequired", true)
.set("complexSelect", true)
.set("filterTarget", function (card, player, target) {
if (
target != _status.event.sourcex &&
!ui.selected.targets.includes(_status.event.sourcex)
)
return false;
return lib.filter.targetEnabled.apply(this, arguments);
})
.set("sourcex", target)
.set("addCount", false);
}
}
const num=player.getHistory('sourceDamage',evt=>{
return evt.getParent(4)==event;
}).reduce((sum,evt)=>sum+evt.num,0);
if(num) await player.draw(num);
if(!game.hasPlayer2(current=>{
return current.getHistory('damage',evt=>{
return evt.getParent(4)==event;
}).length;
})){
const num = player
.getHistory("sourceDamage", (evt) => {
return evt.getParent(4) == event;
})
.reduce((sum, evt) => sum + evt.num, 0);
if (num) await player.draw(num);
if (
!game.hasPlayer2((current) => {
return current.getHistory("damage", (evt) => {
return evt.getParent(4) == event;
}).length;
})
) {
await player.draw(3);
player.addTempSkill('olliantao_buff');
player.addMark('olliantao_buff',3,false);
player.addTempSkill("olliantao_buff");
player.addMark("olliantao_buff", 3, false);
}
},
subSkill:{
backup:{
viewAs:{name:'juedou'},
position:'h',
check:()=>1+Math.random(),
precontent(){
subSkill: {
backup: {
viewAs: { name: "juedou" },
position: "h",
check: () => 1 + Math.random(),
precontent() {
delete event.result.skill;
},
},
buff:{
charlotte:true,
onremove:true,
mod:{
maxHandcard(player,num){
return num+player.countMark('olliantao_buff');
buff: {
charlotte: true,
onremove: true,
mod: {
maxHandcard(player, num) {
return num + player.countMark("olliantao_buff");
},
cardEnabled(card){
if(card.name=='sha') return false;
cardEnabled(card) {
if (card.name == "sha") return false;
},
},
intro:{content:'手牌上限+#,不能使用【杀】'},
intro: { content: "手牌上限+#,不能使用【杀】" },
},
},
},
@ -3056,7 +3116,7 @@ game.import("character", function () {
? ""
: `。若${get.translation(
trigger.player
)}受到了此的伤害你获得其一张牌`
)}受到了此的伤害你获得其一张牌`
}`
);
next.set("norestore", true);
@ -3395,9 +3455,8 @@ game.import("character", function () {
];
[0, 1, 2].forEach((item, index) => {
if (event.list.includes(item)) {
choiceList[
index
] = `<span style="text-decoration: line-through; opacity:0.5; ">${choiceList[index]}</span>`;
choiceList[index] =
`<span style="text-decoration: line-through; opacity:0.5; ">${choiceList[index]}</span>`;
} else choices.push(`选项${get.cnNumber(index + 1, true)}`);
});
game.me
@ -7028,7 +7087,7 @@ game.import("character", function () {
delete stat.gushe;
},
ai: {
combo: "gushe"
combo: "gushe",
},
},
//OL刘老板
@ -12778,10 +12837,13 @@ game.import("character", function () {
(_status.connectMode || current.hasSha())
) {
current
.chooseToUse(function (card, player, event) {
if (get.name(card) != "sha") return false;
return lib.filter.filterCard.apply(this, arguments);
}, "同协:是否对" + get.translation(target) + "使用一张杀?")
.chooseToUse(
function (card, player, event) {
if (get.name(card) != "sha") return false;
return lib.filter.filterCard.apply(this, arguments);
},
"同协:是否对" + get.translation(target) + "使用一张杀?"
)
.set("targetRequired", true)
.set("complexSelect", true)
.set("filterTarget", function (card, player, target) {
@ -17318,10 +17380,13 @@ game.import("character", function () {
"step 0";
var target = trigger.targets[0];
target
.chooseToUse(function (card, player, event) {
if (get.name(card) != "sha") return false;
return lib.filter.filterCard.apply(this, arguments);
}, "武娘:是否对" + get.translation(player) + "使用一张杀?")
.chooseToUse(
function (card, player, event) {
if (get.name(card) != "sha") return false;
return lib.filter.filterCard.apply(this, arguments);
},
"武娘:是否对" + get.translation(player) + "使用一张杀?"
)
.set("targetRequired", true)
.set("complexSelect", true)
.set("filterTarget", function (card, player, target) {
@ -21948,7 +22013,7 @@ game.import("character", function () {
},
},
ai: {
combo: "wylianji"
combo: "wylianji",
},
},
jingong: {
@ -28882,7 +28947,7 @@ game.import("character", function () {
player.changeSkills(["xiaoji"], ["liangzhu"]);
},
ai: {
combo: "liangzhu"
combo: "liangzhu",
},
},
mingshi: {
@ -34505,10 +34570,11 @@ game.import("character", function () {
olyicheng: "易城",
olyicheng_info:
"出牌阶段限一次,你可以亮出牌堆顶的三张牌,然后你可以以任意手牌交换这些牌,若这三张牌的点数和因此增加,则你可以选择用所有手牌交换这三张牌。最后你将这三张牌置于牌堆顶。",
sp_sunce:'SP孙策',
sp_sunce_prefix:'SP',
olliantao:'连讨',
olliantao_info:'出牌阶段开始时你可以令一名其他角色选择一个颜色然后你依次将此颜色的所有手牌当作【决斗】对其使用直到有一方进入濒死状态然后你摸X张牌X为你本次以此法造成的伤害数。若没有角色因本次技能结算受到伤害你摸三张牌本回合手牌上限+3且本回合你不能使用【杀】。',
sp_sunce: "SP孙策",
sp_sunce_prefix: "SP",
olliantao: "连讨",
olliantao_info:
"出牌阶段开始时你可以令一名其他角色选择一个颜色然后你依次将此颜色的所有手牌当作【决斗】对其使用直到有一方进入濒死状态然后你摸X张牌X为你本次以此法造成的伤害数。若没有角色因本次技能结算受到伤害你摸三张牌本回合手牌上限+3且本回合你不能使用【杀】。",
sp_tianji: "天极·皇室宗亲",
sp_sibi: "四弼·辅国文曲",

39
eslint.config.mjs Normal file
View File

@ -0,0 +1,39 @@
import js from "@eslint/js";
import globals from "globals";
export default [
js.configs.recommended,
{
rules: {
"no-console": 0,
"no-constant-condition": [
"error",
{
checkLoops: false,
},
],
"no-irregular-whitespace": [
"error",
{
skipStrings: true,
skipTemplates: true,
},
],
"no-redeclare": 0,
"no-undef": 0,
"no-unused-vars": 0,
"require-yield": 0,
},
languageOptions: {
ecmaVersion: 13,
sourceType: "module",
globals: {
...globals.browser,
...globals.es2015,
...globals.node,
...globals.serviceworker,
...globals.worker,
},
},
},
];

View File

@ -7308,7 +7308,7 @@ export class Game {
for (let i = 0; i < event.config.size; i++) {
ui.window.appendChild(event.nodes[i]);
}
("step 1");
"step 1";
let rand1 = event.config.first;
if (rand1 == "rand") {
rand1 = Math.random() < 0.5;
@ -7350,7 +7350,7 @@ export class Game {
}
game.delay();
lib.init.onfree();
("step 2");
"step 2";
if (event.checkredo()) return;
if (event._skiprest) return;
if (event.side < 2) {
@ -7366,7 +7366,7 @@ export class Game {
event.aiMove();
game.delay();
}
("step 3");
"step 3";
if (typeof event.fast == "number" && get.time() - event.fast <= 1000) {
event.fast = true;
} else {
@ -7401,7 +7401,7 @@ export class Game {
game.delay();
}
}
("step 4");
"step 4";
if (event.checkredo()) return;
if (event.skipnode) event.skipnode.delete();
if (event.replacenode) event.replacenode.delete();
@ -7423,7 +7423,7 @@ export class Game {
}
}
game.delay();
("step 5");
"step 5";
event.prompt("选择" + get.cnNumber(event.config.num) + "名出场武将");
event.enemylist = [];
for (let i = 0; i < event.avatars.length; i++) {
@ -7453,7 +7453,7 @@ export class Game {
event.nodes[i].hide();
}
game.pause();
("step 6");
"step 6";
event.promptbar.delete();
if (ui.cardPileButton) ui.cardPileButton.style.display = "";
lib.onresize.remove(event.resize);

View File

@ -8,45 +8,49 @@ export class GNC {
* @returns
*/
of(fn) {
return this.is.generatorFunc(fn)
? /**
* @param {Parameters<typeof fn>} args
* @returns {Promise<ReturnType<typeof fn>>}
*/
function genCoroutine(...args) {
let gen = fn.apply(this, args);
gen.status = "next";
gen.state = undefined;
const callback = (resolve, reject) => {
let result,
nexts = resolve,
throws = reject;
try {
result = gen[gen.status](gen.state);
} catch (error) {
reject(error);
return;
}
if (!result.done) {
nexts = (item) => {
gen.state = item;
gen.status = "next";
callback(resolve, reject);
};
throws = (err) => {
gen.state = err;
gen.status = "throw";
callback(resolve, reject);
};
}
result = result.value;
Promise.resolve(result).then(nexts, throws);
/**
* @param {Parameters<typeof fn>} args
* @returns {Promise<ReturnType<typeof fn>>}
*/
function genCoroutine(...args) {
/**
* @type {Generator<unknown, any, unknown> & { status: "next" | "throw" , state?: any}}
*/
// @ts-expect-error Must Ok
let gen = fn.apply(this, args);
gen.status = "next";
gen.state = undefined;
const callback = (resolve, reject) => {
let result,
nexts = resolve,
throws = reject;
try {
result = gen[gen.status](gen.state);
} catch (error) {
reject(error);
return;
}
if (!result.done) {
nexts = (item) => {
gen.state = item;
gen.status = "next";
callback(resolve, reject);
};
return new Promise(callback);
}
: (() => {
throw new TypeError("gnc.of needs a GeneratorFunction.");
})();
throws = (err) => {
gen.state = err;
gen.status = "throw";
callback(resolve, reject);
};
}
result = result.value;
Promise.resolve(result).then(nexts, throws);
};
return new Promise(callback);
}
if (!this.is.generatorFunc(fn)) throw new TypeError("gnc.of needs a GeneratorFunction.");
return genCoroutine;
}
is = new Is();
}

13
prettier.config.mjs Normal file
View File

@ -0,0 +1,13 @@
/** @type {import("prettier").Config} */
export default {
arrowParens: "always",
bracketSpacing: true,
endOfLine: "lf",
printWidth: 110,
proseWrap: "preserve",
quoteProps: "as-needed",
semi: true,
tabWidth: 4,
trailingComma: "es5",
useTabs: true,
};