changeCharacter进一步完善

This commit is contained in:
Spmario233 2024-02-15 18:22:08 +08:00
parent 96be0361c7
commit 18ab1ea1b9
2 changed files with 125 additions and 21 deletions

View File

@ -19,31 +19,69 @@ export const Content = {
const newPairs = event.newPairs;
for(let name of newPairs){
if(!lib.character[name]){
console.warn(`警告Player[${player.name}]试图将武将牌变更为不存在的武将`,name);
console.warn(`警告Player[${player.name}]试图将武将牌变更为不存在的武将:`,name);
return;
}
}
const removeSkills = [], addSkills = [];
//变更前后数量相同的情况
if (rawPairs.length == newPairs.length){
for (let i = 0; i<Math.min(2, rawPairs.length); i++){
let rawName = rawPairs[i], newName = newPairs[i];
if (rawName != newName && lib.character[rawName] && lib.character[newName]) {
if(event.log !== false) game.log(player, '将', `#b${get.translation(rawName)}`, '变更为了', `#b${get.translation(newName)}`)
game.broadcastAll((player, rawName, newName)=>{
player.reinit(rawName, newName, null, true);
},player, rawName, newName);
removeSkills.addArray(lib.character[rawName][3]);
addSkills.addArray(lib.character[newName][3]);
//进行Log
if(event.log !== false) {
//变更前后数量相同的情况
if (rawPairs.length == newPairs.length){
for (let i = 0; i<Math.min(2, rawPairs.length); i++){
let rawName = rawPairs[i], newName = newPairs[i];
if (rawName != newName) {
game.log(player, `${i == 0 ? '主' : '副'}将从`, `#b${get.translation(rawName)}`, '变更为了', `#b${get.translation(newName)}`);
}
}
}
else if (rawPairs.length == 1 && newPairs.length == 2){
game.log(player,'将单将', `#b${get.translation(rawPairs[0])}`, '变更为了双将', `#b${get.translation(newPairs[0])}+${get.translation(newPairs[1])}`);
}
else if (rawPairs.length == 2 && newPairs.length == 1){
game.log(player,'将双将', `#b${get.translation(rawPairs[0])}+${get.translation(rawPairs[1])}`, '变更为了单将', `#b${get.translation(newPairs[0])}`);
}
}
if(_status.characterlist){
//确定要失去和获得的技能
//失去技能时全部失去,但获得技能时,非主公角色不能获得主公技。
rawPairs.forEach(name => {
removeSkills.addArray(lib.character[name][3]);
})
newPairs.forEach(name => {
addSkills.addArray(lib.character[name][3].filter(skill => {
const info = get.info(skill);
if (!info || (info.zhuSkill && !player.isZhu2())) return false;
return true;
}));
})
//实际变更武将牌
player.reinit2(newPairs);
//操作武将牌堆
if (_status.characterlist) {
_status.characterlist.removeArray(newPairs);
_status.characterlist.addArray(rawPairs);
}
//变更一下获得前后的技能
player.changeSkills(addSkills, removeSkills);
await player.changeSkills(addSkills, removeSkills);
//变更角色的所属势力。如果新将是双势力,重选一下势力。
if(event.changeGroup !== false){
let newGroups = [];
if (!player.isUnseen(1)) {
newGroups = (get.is.double(player.name1, true) || [get.character(player.name1, 1)]);
}
else if (player.name2 && !player.isUnseen(2)) {
newGroups = (get.is.double(player.name2, true) || [get.character(player.name2, 1)]);
}
if (newGroups.length > 1) {
const newGroup = await player.chooseControl(newGroups).set('prompt','请选择一个新的势力').forResult('control');
if (newGroup != player.group) {
await player.changeGroup(newGroup);
}
}
else if(newGroups.length == 1 && newGroups[0] != player.group){
await player.changeGroup(newGroups[0]);
}
}
},
//变更技能
async changeSkills (event,trigger,player) {

View File

@ -2382,6 +2382,69 @@ export class Player extends HTMLDivElement {
this.firstChild.innerHTML = str;
return this;
}
reinit2(newPairs) {
const player = this;
game.broadcast((player, newPairs) => {
player.reinit2(newPairs);
}, this, newPairs);
const rawPairs = [this.name1];
if (this.name2 && lib.character[this.name2]) rawPairs.push(this.name2);
//单将变单将 & 双将变双将
if (rawPairs.length == newPairs.length){
for (let i = 0; i<Math.min(2, rawPairs.length); i++){
let rawName = rawPairs[i], newName = newPairs[i];
if (rawName != newName && lib.character[rawName] && lib.character[newName]) {
player.reinit(rawName, newName, null, true);
}
}
}
//单将变双将
else if (rawPairs.length == 1 && newPairs.length == 2){
player.name1 = newPairs[0];
player.name2 = newPairs[1];
player.$reinit12(newPairs);
}
//双将变单将
else if (rawPairs.length == 2 && newPairs.length == 1){
player.name1 = newPairs[0];
delete player.name2;
player.$reinit21(newPairs);
}
//修改性别
if (!player.isUnseen(1)) {
player.name = player.name1;
player.sex = get.character(player.name1)[0];
}
else if (!player.isUnseen(2)) {
player.name = player.name2;
player.sex = get.character(player.name2)[0];
}
}
$reinit12(newPairs) {
const player = this;
player.node.avatar.setBackground(newPairs[0], 'character');
player.node.name.innerHTML = get.slimName(newPairs[0]);
player.name2 = newPairs[1];
player.classList.add('fullskin2');
player.node.avatar2.classList.remove('hidden');
player.node.avatar2.setBackground(newPairs[1],'character');
player.node.name2.innerHTML = get.slimName(newPairs[1]);
if (player == game.me && ui.fakeme) {
ui.fakeme.style.backgroundImage = player.node.avatar.style.backgroundImage;
}
}
$reinit21(newPairs) {
const player = this, name = newPairs[0];
player.smoothAvatar(false);
player.node.avatar.setBackground(name,'character');
player.node.name.innerHTML = get.slimName(name);
player.classList.remove('fullskin2');
player.node.avatar2.classList.add('hidden');
player.node.name2.innerHTML = '';
if (player==game.me&&ui.fakeme) {
ui.fakeme.style.backgroundImage=player.node.avatar.style.backgroundImage;
}
}
reinit(from, to, maxHp, online) {
var info1 = lib.character[from];
var info2 = lib.character[to];
@ -2455,14 +2518,13 @@ export class Player extends HTMLDivElement {
player.reinit(from, to, null, true);
player.applySkills(skills);
}, this, from, to, get.skillState(this));
game.addVideo('reinit3', this, {
from: from,
to: to,
hp: this.maxHp,
avatar2: this.name2 == to
});
}
game.addVideo('reinit3', this, {
from: from,
to: to,
hp: this.maxHp,
avatar2: this.name2 == to
});
this.$reinit(from, to, maxHp, online);
this.update();
}
@ -7237,6 +7299,10 @@ export class Player extends HTMLDivElement {
changeSkills(addSkill = [], removeSkill = []){
const next = game.createEvent('changeSkills', false);
next.player = this;
if(!Array.isArray(addSkill) || !Array.isArray(removeSkill)){
console.warn(`警告Player[${this.name}].changeSkills的参数错误应当为数组形式。`);
return;
}
next.addSkill = addSkill.slice(0).unique();
next.removeSkill = removeSkill.slice(0).unique();
next.setContent('changeSkills');