初步建立lib.character类,修改部分读取

This commit is contained in:
Spmario233 2024-04-23 00:23:44 +08:00
parent d47f8ce1b1
commit c7209ee903
8 changed files with 198 additions and 187 deletions

View File

@ -1,5 +1,11 @@
const characters = { const characters = {
sp_key_yuri: ["female", "qun", 4, ["mubing", "ziqu", "diaoling"], ["border:key"]], sp_key_yuri: {
sex: "female",
group: "qun",
hp: 4,
skills: ["mubing", "ziqu", "diaoling"],
groupBorder: "key",
},
key_lucia: ["female", "key", "2/3", ["lucia_duqu", "lucia_zhenren"]], key_lucia: ["female", "key", "2/3", ["lucia_duqu", "lucia_zhenren"]],
key_kyousuke: ["male", "key", 4, ["nk_shekong", "key_huanjie"]], key_kyousuke: ["male", "key", 4, ["nk_shekong", "key_huanjie"]],
key_yuri: ["female", "key", 3, ["yuri_xingdong", "key_huanjie", "yuri_wangxi"], ["zhu"]], key_yuri: ["female", "key", 3, ["yuri_xingdong", "key_huanjie", "yuri_wangxi"], ["zhu"]],

View File

@ -7,7 +7,7 @@ import translates from "./translate.js";
game.import("character", function () { game.import("character", function () {
return { return {
name: "key/index", name: "key",
character: { ...characters }, character: { ...characters },
characterFilter: { characterFilter: {
key_jojiro(mode) { key_jojiro(mode) {

View File

@ -1051,7 +1051,7 @@ game.import("mode", function (lib, game, ui, get, ai, _status) {
list.push(group); list.push(group);
} }
map[group].push(i); map[group].push(i);
if (lib.character[i][4] && lib.character[i][4].includes("zhu")) { if (lib.character[i].isZhugong) {
if (!map_zhu[group]) { if (!map_zhu[group]) {
map_zhu[group] = []; map_zhu[group] = [];
} }
@ -1230,7 +1230,7 @@ game.import("mode", function (lib, game, ui, get, ai, _status) {
list.push(group); list.push(group);
} }
map[group].push(i); map[group].push(i);
if (lib.character[i][4] && lib.character[i][4].includes("zhu")) { if (lib.character[i].isZhugong) {
if (!map_zhu[group]) { if (!map_zhu[group]) {
map_zhu[group] = []; map_zhu[group] = [];
} }
@ -1496,8 +1496,8 @@ game.import("mode", function (lib, game, ui, get, ai, _status) {
if ( if (
get.is.double(result[i][0]) || get.is.double(result[i][0]) ||
(lib.character[result[i][0]] && (lib.character[result[i][0]] &&
lib.character[result[i][0]][1] == "shen" && lib.character[result[i][0]].group == "shen" &&
!lib.character[result[i][0]][4].includes("hiddenSkill")) !lib.character[result[i][0]].hasHiddenSkill)
) )
shen.push(lib.playerOL[i]); shen.push(lib.playerOL[i]);
} }
@ -2098,7 +2098,7 @@ game.import("mode", function (lib, game, ui, get, ai, _status) {
} else { } else {
var bool = false; var bool = false;
for (var j of ix) { for (var j of ix) {
if (lib.character[j][4] && lib.character[j][4].includes("zhu")) { if (lib.character[j].isZhugong) {
bool = true; bool = true;
break; break;
} }
@ -2113,7 +2113,7 @@ game.import("mode", function (lib, game, ui, get, ai, _status) {
if (lib.filter.characterDisabled(i)) continue; if (lib.filter.characterDisabled(i)) continue;
event.list.push(i); event.list.push(i);
list4.push(i); list4.push(i);
if (!stratagemMode && lib.character[i][4] && lib.character[i][4].includes("zhu")) { if (!stratagemMode && lib.character[i].isZhugong) {
list2.push(i); list2.push(i);
} else { } else {
list3.push(i); list3.push(i);
@ -2366,8 +2366,8 @@ game.import("mode", function (lib, game, ui, get, ai, _status) {
game.me._groupChosen = true; game.me._groupChosen = true;
game.me.chooseControl(get.is.double(name, true)).set("prompt", "请选择你的势力"); game.me.chooseControl(get.is.double(name, true)).set("prompt", "请选择你的势力");
} else if ( } else if (
lib.character[name][1] == "shen" && lib.character[name].group == "shen" &&
!lib.character[name][4].includes("hiddenSkill") && !lib.character[name].hasHiddenSkill &&
get.config("choose_group") get.config("choose_group")
) { ) {
var list = lib.group.slice(0); var list = lib.group.slice(0);
@ -2560,7 +2560,7 @@ game.import("mode", function (lib, game, ui, get, ai, _status) {
var pack = lib.characterPack[lib.configOL.characterPack[i]]; var pack = lib.characterPack[lib.configOL.characterPack[i]];
for (var j in pack) { for (var j in pack) {
// if(j=='zuoci') continue; // if(j=='zuoci') continue;
if (lib.character[j]) libCharacter[j] = pack[j]; if (lib.character[j]) libCharacter[j] = lib.character[j];
} }
} }
for (i in lib.characterReplace) { for (i in lib.characterReplace) {
@ -2575,7 +2575,7 @@ game.import("mode", function (lib, game, ui, get, ai, _status) {
list4.addArray(ix); list4.addArray(ix);
var bool = false; var bool = false;
for (var j of ix) { for (var j of ix) {
if (libCharacter[j][4] && libCharacter[j][4].includes("zhu")) { if (libCharacter[j].isZhugong) {
bool = true; bool = true;
break; break;
} }
@ -2597,7 +2597,7 @@ game.import("mode", function (lib, game, ui, get, ai, _status) {
event.list.push(i); event.list.push(i);
event.list2.push(i); event.list2.push(i);
list4.push(i); list4.push(i);
if (libCharacter[i][4] && libCharacter[i][4].includes("zhu")) { if (libCharacter[i].isZhugong) {
list2.push(i); list2.push(i);
} else { } else {
list3.push(i); list3.push(i);
@ -2772,8 +2772,8 @@ game.import("mode", function (lib, game, ui, get, ai, _status) {
if ( if (
get.is.double(result[i][0]) || get.is.double(result[i][0]) ||
(lib.character[result[i][0]] && (lib.character[result[i][0]] &&
lib.character[result[i][0]][1] == "shen" && lib.character[result[i][0]].group == "shen" &&
!lib.character[result[i][0]][4].includes("hiddenSkill")) !lib.character[result[i][0]].hasHiddenSkill)
) )
shen.push(lib.playerOL[i]); shen.push(lib.playerOL[i]);
} }

View File

@ -638,15 +638,8 @@ export class Get {
return "暂无武将介绍"; return "暂无武将介绍";
} }
bordergroup(info, raw) { bordergroup(info, raw) {
if (!Array.isArray(info)) { if(info.groupBorder) return info.groupBorder;
info = lib.character[info]; return raw ? "" : info.group || "";
if (!info) return "";
}
if (Array.isArray(info[4]))
for (const str of info[4]) {
if (typeof str == "string" && str.startsWith("border:")) return str.slice(7);
}
return raw ? "" : info[1] || "";
} }
groupnature(group, method) { groupnature(group, method) {
var nature = lib.groupnature[group]; var nature = lib.groupnature[group];
@ -2938,15 +2931,7 @@ export class Get {
} }
skillintro(name, learn, learn2) { skillintro(name, learn, learn2) {
var str = ""; var str = "";
var infoitem = lib.character[name]; var infoitem = get.character(name);
if (!infoitem) {
for (var itemx in lib.characterPack) {
if (lib.characterPack[itemx][name]) {
infoitem = lib.characterPack[itemx][name];
break;
}
}
}
var skills = infoitem[3]; var skills = infoitem[3];
var opacity; var opacity;
for (var i = 0; i < skills.length; i++) { for (var i = 0; i < skills.length; i++) {

View File

@ -307,6 +307,10 @@ export async function onload(resetGameTimeout) {
} }
for (k in character[i][j]) { for (k in character[i][j]) {
if (j == "character") { if (j == "character") {
if (lib.config.forbidai_user && lib.config.forbidai_user.includes(k)) {
lib.config.forbidai.add(k);
}
if (Array.isArray(character[i][j][k])) {
if (!character[i][j][k][4]) { if (!character[i][j][k][4]) {
character[i][j][k][4] = []; character[i][j][k][4] = [];
} }
@ -316,13 +320,16 @@ export async function onload(resetGameTimeout) {
) { ) {
lib.config.forbidai.add(k); lib.config.forbidai.add(k);
} }
if (lib.config.forbidai_user && lib.config.forbidai_user.includes(k)) {
lib.config.forbidai.add(k);
}
for (var l = 0; l < character[i][j][k][3].length; l++) { for (var l = 0; l < character[i][j][k][3].length; l++) {
lib.skilllist.add(character[i][j][k][3][l]); lib.skilllist.add(character[i][j][k][3][l]);
} }
} }
else{
for (var l = 0; l < character[i][j][k].skills.length; l++) {
lib.skilllist.add(character[i][j][k].skills[l]);
}
}
}
if ( if (
j == "skill" && j == "skill" &&
k[0] == "_" && k[0] == "_" &&
@ -346,6 +353,8 @@ export async function onload(resetGameTimeout) {
nopop: character[i][j][k].nopop, nopop: character[i][j][k].nopop,
derivation: character[i][j][k].derivation, derivation: character[i][j][k].derivation,
}; };
} else if (j === 'character') {
lib.character[k] = character[i][j][k];
} else { } else {
Object.defineProperty( Object.defineProperty(
lib[j], lib[j],
@ -649,8 +658,7 @@ export async function onload(resetGameTimeout) {
console.log(`加载《${lib.extensions[i][0]}》扩展的content时出现错误。`, e); console.log(`加载《${lib.extensions[i][0]}》扩展的content时出现错误。`, e);
if (!lib.config.extension_alert) if (!lib.config.extension_alert)
alert( alert(
`加载《${ `加载《${lib.extensions[i][0]
lib.extensions[i][0]
}扩展的content时出现错误\n该错误本身可能并不影响扩展运行您可以在设置通用无视扩展报错中关闭此弹窗\n${decodeURI( }扩展的content时出现错误\n该错误本身可能并不影响扩展运行您可以在设置通用无视扩展报错中关闭此弹窗\n${decodeURI(
e.stack e.stack
)}` )}`

View File

@ -12,13 +12,23 @@ export class Character {
/** @type { number } */ /** @type { number } */
maxHp; maxHp;
/** @type { number } */ /** @type { number } */
hujia; hujia = 0;
/** @type { string } */ /** @type { string } */
group; group;
/** @type { string } */
groupBorder;
/** @type { string } */
groupInGuozhan;
/** @type { string[] } */ /** @type { string[] } */
skills; skills = [];
/** @type { boolean } */
isZhugong = false;
/** @type { boolean } */
isUnseen = false;
/** @type { boolean } */
hasHiddenSkill = false;
/** @type { Array } */ /** @type { Array } */
trashBin; trashBin = [];
/** /**
* @param { Array|Object } [data] * @param { Array|Object } [data]
*/ */
@ -31,15 +41,35 @@ export class Character {
this.hujia = get.infoHujia(data[2]); this.hujia = get.infoHujia(data[2]);
this.skills = get.copy(data[3] || []); this.skills = get.copy(data[3] || []);
this.trashBin = get.copy(data[4] || []); this.trashBin = get.copy(data[4] || []);
Character.convertTrashToProperties(this, this.trashBin);
} }
else if (get.is.object(data)) { else if (get.is.object(data)) {
this.sex = data.sex; Object.assign(this, data);
this.group = data.group || ''; if(typeof this.maxHp !== 'number') this.maxHp = this.hp;
this.hp = data.hp || 1; }
this.maxHp = data.maxHp || this.hp; };
this.hujia = data.hujia || 0; /**
this.skills = get.copy(data.skills || []); * @param { Character } character
this.trashBin = get.copy(data.trashBin || []); * @param { Array } trash
*/
static convertTrashToProperties(character, trash){
for(let i = 0; i < trash.length; i++){
let item = trash[i];
if (i === 0 && lib.group.includes(item)){
character.groupInGuozhan = item;
}
else if(item === 'zhu'){
character.isZhugong = true;
}
else if(item === 'unseen'){
character.isUnseen = true;
}
else if(item === 'hiddenSkill'){
character.hasHiddenSkill = true;
}
else if(item.startsWith('border:')){
character.groupBorder = item.slice(7);
}
} }
}; };
/** /**

View File

@ -2358,17 +2358,14 @@ export class Player extends HTMLDivElement {
} }
var info = lib.character[character]; var info = lib.character[character];
if (!info) { if (!info) {
info = ["", "", 1, [], []]; info = new lib.element.Character(["", "", 1, [], []]);
} }
if (!info[4]) { var skills = info.skills.slice(0);
info[4] = [];
}
var skills = info[3].slice(0);
this.clearSkills(true); this.clearSkills(true);
var hp1 = get.infoHp(info[2]); var hp1 = info.hp;
var maxHp1 = get.infoMaxHp(info[2]); var maxHp1 = info.maxHp;
var hujia1 = get.infoHujia(info[2]); var hujia1 = info.hujia;
this.name = character; this.name = character;
this.name1 = character; this.name1 = character;
@ -2377,8 +2374,8 @@ export class Player extends HTMLDivElement {
name: character, name: character,
name2: character2, name2: character2,
}; };
this.sex = info[0]; this.sex = info.sex;
this.group = info[1]; this.group = info.group;
this.hp = hp1; this.hp = hp1;
this.maxHp = maxHp1; this.maxHp = maxHp1;
this.hujia = hujia1; this.hujia = hujia1;
@ -2389,7 +2386,7 @@ export class Player extends HTMLDivElement {
if (this.classList.contains("minskin") && this.node.name.querySelectorAll("br").length >= 4) { if (this.classList.contains("minskin") && this.node.name.querySelectorAll("br").length >= 4) {
this.node.name.classList.add("long"); this.node.name.classList.add("long");
} }
if (info[4].includes("hiddenSkill") && !this.noclick) { if (info.hasHiddenSkill && !this.noclick) {
if (!this.hiddenSkills) this.hiddenSkills = []; if (!this.hiddenSkills) this.hiddenSkills = [];
this.hiddenSkills.addArray(skills); this.hiddenSkills.addArray(skills);
skills = []; skills = [];
@ -2401,16 +2398,13 @@ export class Player extends HTMLDivElement {
if (character2 && lib.character[character2]) { if (character2 && lib.character[character2]) {
var info2 = lib.character[character2]; var info2 = lib.character[character2];
if (!info2) { if (!info2) {
info2 = ["", "", 1, [], []]; info2 = new lib.element.Character(["", "", 1, [], []]);
}
if (!info2[4]) {
info2[4] = [];
} }
this.name2 = character2; this.name2 = character2;
var hp2 = get.infoHp(info2[2]); var hp2 = info2.hp;
var maxHp2 = get.infoMaxHp(info2[2]); var maxHp2 = info2.maxHp;
var hujia2 = get.infoHujia(info2[2]); var hujia2 = info2.hujia;
this.hujia += hujia2; this.hujia += hujia2;
var double_hp; var double_hp;
if (_status.connectMode || get.mode() == "single") { if (_status.connectMode || get.mode() == "single") {
@ -2445,12 +2439,12 @@ export class Player extends HTMLDivElement {
this.hp = hp1 + hp2 - 3; this.hp = hp1 + hp2 - 3;
} }
} }
if (info2[4].includes("hiddenSkill") && !this.noclick) { if (info2.hasHiddenSkill && !this.noclick) {
if (!this.hiddenSkills) this.hiddenSkills = []; if (!this.hiddenSkills) this.hiddenSkills = [];
this.hiddenSkills.addArray(info2[3]); this.hiddenSkills.addArray(info2.skills);
hidden = true; hidden = true;
skills.add("g_hidden_ai"); skills.add("g_hidden_ai");
} else skills = skills.concat(info2[3]); } else skills = skills.concat(info2.skills);
} }
if (this.storage.nohp || hidden) { if (this.storage.nohp || hidden) {
this.storage.rawHp = this.hp; this.storage.rawHp = this.hp;
@ -2493,10 +2487,7 @@ export class Player extends HTMLDivElement {
this.classList.add("fullskin"); this.classList.add("fullskin");
var info = lib.character[character]; var info = lib.character[character];
if (!info) { if (!info) {
info = ["", "", 1, [], []]; info = new lib.element.Character(["", "", 1, [], []]);
}
if (!info[4]) {
info[4] = [];
} }
if (!game.minskin && get.is.newLayout() && !info[4].includes("minskin")) { if (!game.minskin && get.is.newLayout() && !info[4].includes("minskin")) {
@ -2524,7 +2515,7 @@ export class Player extends HTMLDivElement {
if (this.classList.contains("minskin") && this.node.name.querySelectorAll("br").length >= 4) { if (this.classList.contains("minskin") && this.node.name.querySelectorAll("br").length >= 4) {
this.node.name.classList.add("long"); this.node.name.classList.add("long");
} }
if (info[4].includes("hiddenSkill") && !this.noclick) { if (info.hasHiddenSkill && !this.noclick) {
if (!_status.video && get.mode() != "guozhan") this.classList.add("unseen_show"); if (!_status.video && get.mode() != "guozhan") this.classList.add("unseen_show");
this.classList.add(_status.video ? "unseen_v" : "unseen"); this.classList.add(_status.video ? "unseen_v" : "unseen");
if (!this.node.name_seat && !_status.video) { if (!this.node.name_seat && !_status.video) {
@ -2539,10 +2530,7 @@ export class Player extends HTMLDivElement {
if (character2 && lib.character[character2]) { if (character2 && lib.character[character2]) {
var info2 = lib.character[character2]; var info2 = lib.character[character2];
if (!info2) { if (!info2) {
info2 = ["", "", 1, [], []]; info2 = new lib.element.Character(["", "", 1, [], []]);
}
if (!info2[4]) {
info2[4] = [];
} }
this.classList.add("fullskin2"); this.classList.add("fullskin2");
this.node.avatar2.setBackground(character2, "character"); this.node.avatar2.setBackground(character2, "character");
@ -2550,7 +2538,7 @@ export class Player extends HTMLDivElement {
this.name2 = character2; this.name2 = character2;
this.node.count.classList.add("p2"); this.node.count.classList.add("p2");
if (info2[4].includes("hiddenSkill") && !this.noclick) { if (info2.hasHiddenSkill && !this.noclick) {
if (!_status.video && get.mode() != "guozhan") this.classList.add("unseen2_show"); if (!_status.video && get.mode() != "guozhan") this.classList.add("unseen2_show");
this.classList.add(_status.video ? "unseen2_v" : "unseen2"); this.classList.add(_status.video ? "unseen2_v" : "unseen2");
} }

View File

@ -1170,8 +1170,7 @@ export class Library {
unfrequent: true, unfrequent: true,
item: {}, item: {},
intro: () => intro: () =>
`获取在线扩展时的地址。当前地址:${document.createElement("br").outerHTML}${ `获取在线扩展时的地址。当前地址:${document.createElement("br").outerHTML}${lib.config.extension_sources[lib.config.extension_source]
lib.config.extension_sources[lib.config.extension_source]
}`, }`,
}, },
extension_create: { extension_create: {
@ -11139,8 +11138,7 @@ export class Library {
content: (storage, player) => { content: (storage, player) => {
const stratagemFuryMax = _status.stratagemFuryMax, const stratagemFuryMax = _status.stratagemFuryMax,
fury = storage || 0; fury = storage || 0;
return `当前怒气值:${ return `当前怒气值:${typeof stratagemFuryMax == "number" ? `${fury}/${stratagemFuryMax}` : fury
typeof stratagemFuryMax == "number" ? `${fury}/${stratagemFuryMax}` : fury
}`; }`;
}, },
}, },
@ -11295,8 +11293,7 @@ export class Library {
)}点怒气${prompt()}`; )}点怒气${prompt()}`;
span.appendChild(li); span.appendChild(li);
}); });
return `当你需要使用位于“强化表”内的非虚拟卡牌时,你可以消耗对应数量的怒气将其强化并使用。${ return `当你需要使用位于“强化表”内的非虚拟卡牌时,你可以消耗对应数量的怒气将其强化并使用。${document.createElement("hr").outerHTML
document.createElement("hr").outerHTML
}${span.outerHTML}`; }${span.outerHTML}`;
}, },
onuse: (result, player) => { onuse: (result, player) => {
@ -12778,15 +12775,12 @@ export class Library {
}, },
}, },
}; };
character = new Proxy( character = new Proxy({}, {
{},
{
set(target, prop, newValue) { set(target, prop, newValue) {
newValue = new lib.element.Character(newValue); if(!(newValue instanceof Element.Character)) newValue = new Element.Character(newValue);
return Reflect.set(target, prop, newValue); return Reflect.set(target, prop, newValue);
} }
} });
);
perfectPair = {}; perfectPair = {};
cardPile = {}; cardPile = {};
message = { message = {