From a91c1f4219b96be310d1d22bccbaae9ea1c59beb Mon Sep 17 00:00:00 2001 From: Spmario233 Date: Thu, 15 Feb 2024 02:31:22 +0800 Subject: [PATCH] =?UTF-8?q?changeCharacter=E5=A2=9E=E5=8A=A0=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E6=A3=80=E6=B5=8B=EF=BC=8C=E6=95=B4=E5=90=88=5Fstatus?= =?UTF-8?q?.characterlist=E7=9A=84=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- character/diy.js | 12 ++++-------- noname/library/element/content.js | 30 +++++++++++++++++++++++++----- noname/library/element/player.js | 17 ++++++++++++++--- 3 files changed, 43 insertions(+), 16 deletions(-) diff --git a/character/diy.js b/character/diy.js index 0d906d141..e5baa65b7 100755 --- a/character/diy.js +++ b/character/diy.js @@ -4625,7 +4625,7 @@ game.import('character',function(lib,game,ui,get,ai,_status){ content(){ 'step 0' player.awakenSkill('yukito_yaxiang'); - player.reinit('key_yukito','key_crow'); + player.reinitCharacter('key_yukito', 'key_crow', false); 'step 1' if(target.hp<3) target.recover(3-target.hp); 'step 2' @@ -7815,9 +7815,7 @@ game.import('character',function(lib,game,ui,get,ai,_status){ player.recover(num); player.draw(num); if(_status.characterlist&&_status.characterlist.includes('key_midori')){ - player.reinit('key_mio','key_midori',false); - _status.characterlist.remove('key_midori'); - _status.characterlist.add('key_mio'); + player.reinitCharacter('key_mio','key_midori', false); } }, }, @@ -7890,9 +7888,7 @@ game.import('character',function(lib,game,ui,get,ai,_status){ player.recover(num); player.draw(num); if(_status.characterlist&&_status.characterlist.includes('key_mio')){ - player.reinit('key_midori','key_mio',false); - _status.characterlist.remove('key_mio'); - _status.characterlist.add('key_midori'); + player.reinitCharacter('key_midori', 'key_mio', false); } }, }, @@ -10754,7 +10750,7 @@ game.import('character',function(lib,game,ui,get,ai,_status){ content(){ 'step 0' player.awakenSkill('umi_qihuan'); - player.reinit('key_umi','key_umi2'); + player.reinitCharacter('key_umi', 'key_umi2', false); player.recover(game.countGroup()||1); if(!game.dead.length) event.finish(); 'step 1' diff --git a/noname/library/element/content.js b/noname/library/element/content.js index 1975c9900..bc3ca9291 100644 --- a/noname/library/element/content.js +++ b/noname/library/element/content.js @@ -14,24 +14,34 @@ export const Content = { //变更武将牌 async changeCharacter(event,trigger,player) { const rawPairs = [player.name1]; - if (player.name2) rawPairs.push(player.name2); + if (player.name2 && lib.character[player.name2]) rawPairs.push(player.name2); event.rawPairs = rawPairs; const newPairs = event.newPairs; + for(let name of newPairs){ + if(!lib.character[name]){ + console.warn(`警告:Player[${player.name}]试图将武将牌变更为不存在的武将“${name}”`); + return; + } + } const removeSkills = [], addSkills = []; //变更前后数量相同的情况 if (rawPairs.length == newPairs.length){ for (let i = 0; i{ player.reinit(rawName, newName, null, true); },player, rawName, newName); removeSkills.addArray(lib.character[rawName][3]); - addSkills.addArray(lib.character[newName][3]) + addSkills.addArray(lib.character[newName][3]); } } } + if(_status.characterlist){ + _status.characterlist.removeArray(newPairs); + _status.characterlist.addArray(rawPairs); + } //变更一下获得前后的技能 player.changeSkills(addSkills, removeSkills); }, @@ -54,8 +64,18 @@ export const Content = { event.$handle(player, event.addSkill, event.removeSkill, event); } else { - if(event.addSkill.length) player.addSkillLog(event.addSkill); - if(event.removeSkill.length) player.removeSkillLog(event.removeSkill); + if(event.addSkill.length){ + player.addSkill(event.addSkill); + game.log(player, '获得了技能', ...event.addSkill.map(i => { + return '#g【' + get.translation(i) + '】'; + })); + } + if(event.removeSkill.length){ + player.removeSkill(event.removeSkill); + game.log(player, '失去了技能', ...event.removeSkill.map(i => { + return '#g【' + get.translation(i) + '】'; + })); + } } //手动触发时机 await event.trigger('changeSkillsEnd'); diff --git a/noname/library/element/player.js b/noname/library/element/player.js index fb6fca479..9d0d13b48 100644 --- a/noname/library/element/player.js +++ b/noname/library/element/player.js @@ -1560,7 +1560,7 @@ export class Player extends HTMLDivElement { * @param { String } to * @returns { GameEventPromise } */ - reinitCharacter(from, to){ + reinitCharacter(from, to, log = true){ const rawPairs = [this.name1]; if (this.name2) rawPairs.push(this.name2); for (let i=0; i