changeCharacter初步构建,添加reinitCharacter的语法糖

This commit is contained in:
Spmario233 2024-02-15 02:09:34 +08:00
parent 80f9d242ef
commit 79b7be9272
3 changed files with 103 additions and 53 deletions

View File

@ -618,7 +618,7 @@ game.import('character',function(lib,game,ui,get,ai,_status){
player.addMark('dcbianzhuang',1,false);
if(player.countMark('dcbianzhuang')>2){
player.storage.dcbianzhuang_inited=true;
player.reinit('zhutiexiong','wu_zhutiexiong');
player.reinitCharacter('zhutiexiong','wu_zhutiexiong');
}
}
},

View File

@ -11,25 +11,49 @@ export const Content = {
emptyEvent: () => {
event.trigger(event.name);
},
//变更武将牌
async changeCharacter(event,trigger,player) {
const rawPairs = [player.name1];
if (player.name2) rawPairs.push(player.name2);
event.rawPairs = rawPairs;
const newPairs = event.newPairs;
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]) {
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])
}
}
}
//变更一下获得前后的技能
player.changeSkills(addSkills, removeSkills);
},
//变更技能
async changeSkills (event,trigger,player) {
//去重检查
event.addSkill.unique();
event.removeSkill.unique();
const duplicatedSkills = event.addSkill.filter(skill => event.removeSkill.includes(skill));
if(duplicatedSkills.length){
if (duplicatedSkills.length) {
event.addSkill.removeArray(duplicatedSkills);
event.removeSkill.removeArray(duplicatedSkills);
}
if(!event.addSkill.length&&!event.removeSkill.length) return;
if (!event.addSkill.length&&!event.removeSkill.length) return;
//手动触发时机
await event.trigger('changeSkillsBefore');
await event.trigger('changeSkillsBegin');
//处理失去和获得的技能
if(event.$handle){
event.$handle(player,event.addSkill,event.removeSkill,event);
if (event.$handle) {
event.$handle(player, event.addSkill, event.removeSkill, event);
}
else{
else {
if(event.addSkill.length) player.addSkillLog(event.addSkill);
if(event.removeSkill.length) player.removeSkillLog(event.removeSkill);
}

View File

@ -1555,6 +1555,33 @@ export class Player extends HTMLDivElement {
if (typeof savable == 'function') savable = savable(card, this, target);
return savable;
}
/**
* @param { String } from
* @param { String } to
* @returns { GameEventPromise }
*/
reinitCharacter(from, to){
const rawPairs = [this.name1];
if (this.name2) rawPairs.push(this.name2);
for (let i=0; i<rawPairs.length; i++){
if (rawPairs[i] == from) {
rawPairs[i] = to;
break;
}
}
return this.changeCharacter(rawPairs);
}
/**
* @param { String[] } newPairs
* @returns { GameEventPromise }
*/
changeCharacter(newPairs){
const next = game.createEvent('changeCharacter');
next.player = this;
next.newPairs = newPairs;
next.setContent('changeCharacter');
return next;
}
/**
* @param { 0 | 1 | 2 } num
* @param { false } [log]
@ -2367,64 +2394,63 @@ export class Player extends HTMLDivElement {
else {
return this;
}
if (online) {
return;
}
for (var i = 0; i < info1[3].length; i++) {
this.removeSkill(info1[3][i]);
}
for (var i = 0; i < info2[3].length; i++) {
var info = get.info(info2[3][i]);
if (info && info.zhuSkill && !this.isZhu2()) continue;
this.addSkill(info2[3][i]);
}
if (Array.isArray(maxHp)) {
this.maxHp = maxHp[1];
this.hp = maxHp[0];
}
else {
var num;
if (maxHp === false) {
num = 0;
if (!online) {
for (var i = 0; i < info1[3].length; i++) {
this.removeSkill(info1[3][i]);
}
for (var i = 0; i < info2[3].length; i++) {
var info = get.info(info2[3][i]);
if (info && info.zhuSkill && !this.isZhu2()) continue;
this.addSkill(info2[3][i]);
}
if (Array.isArray(maxHp)) {
this.maxHp = maxHp[1];
this.hp = maxHp[0];
}
else {
if (typeof maxHp != 'number') {
maxHp = get.infoMaxHp(info2[2]);
var num;
if (maxHp === false) {
num = 0;
}
num = maxHp - get.infoMaxHp(info1[2]);
}
if (typeof this.singleHp == 'boolean') {
if (num % 2 != 0) {
if (this.singleHp) {
this.maxHp += (num + 1) / 2;
this.singleHp = false;
else {
if (typeof maxHp != 'number') {
maxHp = get.infoMaxHp(info2[2]);
}
num = maxHp - get.infoMaxHp(info1[2]);
}
if (typeof this.singleHp == 'boolean') {
if (num % 2 != 0) {
if (this.singleHp) {
this.maxHp += (num + 1) / 2;
this.singleHp = false;
}
else {
this.maxHp += (num - 1) / 2;
this.singleHp = true;
if (!game.online) {
this.doubleDraw();
}
}
}
else {
this.maxHp += (num - 1) / 2;
this.singleHp = true;
if (!game.online) {
this.doubleDraw();
}
this.maxHp += num / 2;
}
}
else {
this.maxHp += num / 2;
this.maxHp += num;
}
}
else {
this.maxHp += num;
}
game.broadcast(function (player, from, to, skills) {
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.broadcast(function (player, from, to, skills) {
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
});
this.$reinit(from, to, maxHp, online);
this.update();