创建lib.element.Character类

This commit is contained in:
Spmario233 2024-04-22 23:18:50 +08:00
parent 1a8746c4d5
commit d47f8ce1b1
4 changed files with 116 additions and 2 deletions

View File

@ -604,7 +604,7 @@ export class Get {
let info = lib.character[name];
if (!info) {
const pack = Object.keys(lib.characterPack).find((pack) => name in lib.characterPack[pack]);
if (pack) info = lib.characterPack[pack][name];
if (pack) info = new lib.element.Character(lib.characterPack[pack][name]);
}
if (typeof num === "number") {
if (!info) info = [];

View File

@ -0,0 +1,98 @@
import { get } from "../../get/index.js";
import { game } from "../../game/index.js";
import { lib } from "../index.js";
import { _status } from "../../status/index.js";
import { ui } from "../../ui/index.js";
export class Character {
/** @type { string } */
sex;
/** @type { number } */
hp;
/** @type { number } */
maxHp;
/** @type { number } */
hujia;
/** @type { string } */
group;
/** @type { string[] } */
skills;
/** @type { Array } */
trashBin;
/**
* @param { Array|Object } [data]
*/
constructor(data) {
if (Array.isArray(data)) {
this.sex = data[0];
this.group = data[1];
this.hp = get.infoHp(data[2]);
this.maxHp = get.infoMaxHp(data[2]);
this.hujia = get.infoHujia(data[2]);
this.skills = get.copy(data[3] || []);
this.trashBin = get.copy(data[4] || []);
}
else if (get.is.object(data)) {
this.sex = data.sex;
this.group = data.group || '';
this.hp = data.hp || 1;
this.maxHp = data.maxHp || this.hp;
this.hujia = data.hujia || 0;
this.skills = get.copy(data.skills || []);
this.trashBin = get.copy(data.trashBin || []);
}
};
/**
* @deprecated
*/
get 0() {
return this.sex;
};
set 0(sex) {
this.sex = sex;
};
/**
* @deprecated
*/
get 1() {
return this.group;
};
set 1(group) {
this.group = group;
};
/**
* @deprecated
*/
get 2() {
if (this.hujia > 0) return `${this.hp}/${this.maxHp}/${this.hujia}`;
else if (this.hp !== this.maxHp) return `${this.hp}/${this.maxHp}`;
return this.hp;
};
set 2(hp) {
this.hp = get.infoHp(hp);
this.maxHp = get.infoMaxHp(hp);
this.hujia = get.infoHujia(hp);
};
/**
* @deprecated
*/
get 3() {
return this.skills;
};
set 3(skills) {
this.skills = skills;
};
/**
* @deprecated
*/
get 4() {
return this.trashBin;
};
set 4(trashBin) {
this.trashBin = trashBin;
};
}

View File

@ -10,3 +10,4 @@ export { GameEventPromise } from "./gameEventPromise.js";
export { NodeWS } from "./nodeWS.js";
export { Player } from "./player.js";
export { VCard } from "./vcard.js";
export { Character } from "./character.js"

View File

@ -10108,6 +10108,7 @@ export class Library {
Control: Element.Control,
Client: Element.Client,
NodeWS: Element.NodeWS,
Character: Element.Character,
ws: {
onopen: function () {
if (_status.connectCallback) {
@ -10213,6 +10214,12 @@ export class Library {
get nodews() {
return this.NodeWS.prototype;
},
/**
* @legacy Use {@link lib.element.Character.prototype} instead.
*/
get character() {
return this.Character.prototype;
},
};
card = {
/**
@ -12771,7 +12778,15 @@ export class Library {
},
},
};
character = {};
character = new Proxy(
{},
{
set(target, prop, newValue){
newValue = new lib.element.Character(newValue);
return Reflect.set(target, prop, newValue);
}
}
);
perfectPair = {};
cardPile = {};
message = {