changeCharacter增加参数检测,整合_status.characterlist的操作
This commit is contained in:
parent
79b7be9272
commit
a91c1f4219
|
@ -4625,7 +4625,7 @@ game.import('character',function(lib,game,ui,get,ai,_status){
|
||||||
content(){
|
content(){
|
||||||
'step 0'
|
'step 0'
|
||||||
player.awakenSkill('yukito_yaxiang');
|
player.awakenSkill('yukito_yaxiang');
|
||||||
player.reinit('key_yukito','key_crow');
|
player.reinitCharacter('key_yukito', 'key_crow', false);
|
||||||
'step 1'
|
'step 1'
|
||||||
if(target.hp<3) target.recover(3-target.hp);
|
if(target.hp<3) target.recover(3-target.hp);
|
||||||
'step 2'
|
'step 2'
|
||||||
|
@ -7815,9 +7815,7 @@ game.import('character',function(lib,game,ui,get,ai,_status){
|
||||||
player.recover(num);
|
player.recover(num);
|
||||||
player.draw(num);
|
player.draw(num);
|
||||||
if(_status.characterlist&&_status.characterlist.includes('key_midori')){
|
if(_status.characterlist&&_status.characterlist.includes('key_midori')){
|
||||||
player.reinit('key_mio','key_midori',false);
|
player.reinitCharacter('key_mio','key_midori', false);
|
||||||
_status.characterlist.remove('key_midori');
|
|
||||||
_status.characterlist.add('key_mio');
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -7890,9 +7888,7 @@ game.import('character',function(lib,game,ui,get,ai,_status){
|
||||||
player.recover(num);
|
player.recover(num);
|
||||||
player.draw(num);
|
player.draw(num);
|
||||||
if(_status.characterlist&&_status.characterlist.includes('key_mio')){
|
if(_status.characterlist&&_status.characterlist.includes('key_mio')){
|
||||||
player.reinit('key_midori','key_mio',false);
|
player.reinitCharacter('key_midori', 'key_mio', false);
|
||||||
_status.characterlist.remove('key_mio');
|
|
||||||
_status.characterlist.add('key_midori');
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -10754,7 +10750,7 @@ game.import('character',function(lib,game,ui,get,ai,_status){
|
||||||
content(){
|
content(){
|
||||||
'step 0'
|
'step 0'
|
||||||
player.awakenSkill('umi_qihuan');
|
player.awakenSkill('umi_qihuan');
|
||||||
player.reinit('key_umi','key_umi2');
|
player.reinitCharacter('key_umi', 'key_umi2', false);
|
||||||
player.recover(game.countGroup()||1);
|
player.recover(game.countGroup()||1);
|
||||||
if(!game.dead.length) event.finish();
|
if(!game.dead.length) event.finish();
|
||||||
'step 1'
|
'step 1'
|
||||||
|
|
|
@ -14,24 +14,34 @@ export const Content = {
|
||||||
//变更武将牌
|
//变更武将牌
|
||||||
async changeCharacter(event,trigger,player) {
|
async changeCharacter(event,trigger,player) {
|
||||||
const rawPairs = [player.name1];
|
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;
|
event.rawPairs = rawPairs;
|
||||||
const newPairs = event.newPairs;
|
const newPairs = event.newPairs;
|
||||||
|
for(let name of newPairs){
|
||||||
|
if(!lib.character[name]){
|
||||||
|
console.warn(`警告:Player[${player.name}]试图将武将牌变更为不存在的武将“${name}”`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
const removeSkills = [], addSkills = [];
|
const removeSkills = [], addSkills = [];
|
||||||
//变更前后数量相同的情况
|
//变更前后数量相同的情况
|
||||||
if (rawPairs.length == newPairs.length){
|
if (rawPairs.length == newPairs.length){
|
||||||
for (let i = 0; i<Math.min(2, rawPairs.length); i++){
|
for (let i = 0; i<Math.min(2, rawPairs.length); i++){
|
||||||
let rawName = rawPairs[i], newName = newPairs[i];
|
let rawName = rawPairs[i], newName = newPairs[i];
|
||||||
if (rawName != newName && lib.character[rawName] && lib.character[newName]) {
|
if (rawName != newName && lib.character[rawName] && lib.character[newName]) {
|
||||||
game.log(player, '将', `#b${get.translation(rawName)}`, '变更为了', `#b${get.translation(newName)}`)
|
if(event.log !== false) game.log(player, '将', `#b${get.translation(rawName)}`, '变更为了', `#b${get.translation(newName)}`)
|
||||||
game.broadcastAll((player, rawName, newName)=>{
|
game.broadcastAll((player, rawName, newName)=>{
|
||||||
player.reinit(rawName, newName, null, true);
|
player.reinit(rawName, newName, null, true);
|
||||||
},player, rawName, newName);
|
},player, rawName, newName);
|
||||||
removeSkills.addArray(lib.character[rawName][3]);
|
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);
|
player.changeSkills(addSkills, removeSkills);
|
||||||
},
|
},
|
||||||
|
@ -54,8 +64,18 @@ export const Content = {
|
||||||
event.$handle(player, event.addSkill, event.removeSkill, event);
|
event.$handle(player, event.addSkill, event.removeSkill, event);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(event.addSkill.length) player.addSkillLog(event.addSkill);
|
if(event.addSkill.length){
|
||||||
if(event.removeSkill.length) player.removeSkillLog(event.removeSkill);
|
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');
|
await event.trigger('changeSkillsEnd');
|
||||||
|
|
|
@ -1560,7 +1560,7 @@ export class Player extends HTMLDivElement {
|
||||||
* @param { String } to
|
* @param { String } to
|
||||||
* @returns { GameEventPromise }
|
* @returns { GameEventPromise }
|
||||||
*/
|
*/
|
||||||
reinitCharacter(from, to){
|
reinitCharacter(from, to, log = true){
|
||||||
const rawPairs = [this.name1];
|
const rawPairs = [this.name1];
|
||||||
if (this.name2) rawPairs.push(this.name2);
|
if (this.name2) rawPairs.push(this.name2);
|
||||||
for (let i=0; i<rawPairs.length; i++){
|
for (let i=0; i<rawPairs.length; i++){
|
||||||
|
@ -1569,16 +1569,27 @@ export class Player extends HTMLDivElement {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this.changeCharacter(rawPairs);
|
return this.changeCharacter(rawPairs, log);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @param { String[] } newPairs
|
* @param { String[] } newPairs
|
||||||
* @returns { GameEventPromise }
|
* @returns { GameEventPromise }
|
||||||
*/
|
*/
|
||||||
changeCharacter(newPairs){
|
changeCharacter(newPairs, log = true){
|
||||||
|
if (!Array.isArray(newPairs)){
|
||||||
|
console.warn(`警告:Player[${this.name}].changeCharacter填写了一个错误的参数:`,newPairs);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for(let name of newPairs){
|
||||||
|
if(!lib.character[name]){
|
||||||
|
console.warn(`警告:Player[${this.name}]试图将武将牌变更为不存在的武将:`,name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
const next = game.createEvent('changeCharacter');
|
const next = game.createEvent('changeCharacter');
|
||||||
next.player = this;
|
next.player = this;
|
||||||
next.newPairs = newPairs;
|
next.newPairs = newPairs;
|
||||||
|
next.log = log;
|
||||||
next.setContent('changeCharacter');
|
next.setContent('changeCharacter');
|
||||||
return next;
|
return next;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue