添加事件化版本的addTempSkills,addAdditionalSkills和removeAdditionalSkills

This commit is contained in:
Spmario233 2024-02-16 23:23:51 +08:00
parent 33c7439149
commit bbfa0e47e9
3 changed files with 110 additions and 44 deletions

View File

@ -17639,10 +17639,7 @@ game.import('character',function(lib,game,ui,get,ai,_status){
'step 1'
if(result.bool){
var skills=lib.skill.junkyuheng.derivation.randomGets(result.cards.length);
player.changeSkills(skills,[]).set('$handle',(player,skills)=>{
player.addAdditionalSkill('junkyuheng',skills);
game.log(player,'获得了以下技能:','#g'+get.translation(skills));
});
player.addAdditionalSkills('junkyuheng',skills);
}
},
group:'junkyuheng_remove',
@ -17655,13 +17652,10 @@ game.import('character',function(lib,game,ui,get,ai,_status){
filter(event,player){
return player.additionalSkills.junkyuheng&&player.additionalSkills.junkyuheng.length>0;
},
content(){
async content(event,trigger,player){
const skills = player.additionalSkills.junkyuheng;
player.draw(skills.length);
player.changeSkills([],skills).set('$handle',(player,addSkills,removeSkills)=>{
game.log(player,'失去了以下技能:','#g'+get.translation(removeSkills));
for(let skill of removeSkills) player.removeAdditionalSkill('junkyuheng',skill);
});
await player.draw(skills.length);
await player.removeAdditionalSkills('junkyuheng');
},
},
},
@ -17728,7 +17722,6 @@ game.import('character',function(lib,game,ui,get,ai,_status){
'step 2'
if(result.bool){
var skills=result.links;
game.log(player,'失去了以下技能:','#g'+get.translation(skills));
player.removeSkills(skills.slice(0));
}
var list=lib.skill.junkdili.derivation;

View File

@ -24791,8 +24791,7 @@ game.import('character',function(lib,game,ui,get,ai,_status){
}
if(event.num>1) player.draw(2);
if(event.num>2){
player.addTempSkill('lingren_jianxiong',{player:'phaseBegin'});
player.addTempSkill('lingren_xingshang',{player:'phaseBegin'});
player.addTempSkills(['lingren_jianxiong','lingren_xingshang'],{player:'phaseBegin'});
}
},
ai:{
@ -25991,7 +25990,7 @@ game.import('character',function(lib,game,ui,get,ai,_status){
},
translate:{
"xinfu_lingren":"凌人",
"xinfu_lingren_info":"每回合限一次。当你于出牌阶段内使用带有「伤害」标签的基本牌或普通锦囊牌指定目标后你可以猜测其中的一个目标的手牌中是否有基本牌锦囊牌或装备牌。若你猜中的项目数≥1此牌对该角色的伤害+1≥2你摸两张牌≥3你获得技能〖奸雄〗和〖行殇〗直到下回合开始。",
"xinfu_lingren_info":"每回合限一次。当你于出牌阶段内使用带有「伤害」标签的基本牌或普通锦囊牌指定目标后你可以猜测其中的一个目标的手牌中是否有基本牌锦囊牌或装备牌。若你猜中的项目数≥1此牌对该角色的伤害+1≥2你摸两张牌≥3你获得技能〖奸雄〗和〖行殇〗直到你的下回合开始。",
"lingren_adddamage":"凌人",
"lingren_adddamage_info":"",
"lingren_jianxiong":"奸雄",

View File

@ -602,7 +602,7 @@ export class Player extends HTMLDivElement {
scope = _scope;
if (skill.contentFuns.length > 0) createContent();
return this;
}
},
};
}
/**
@ -7377,35 +7377,64 @@ export class Player extends HTMLDivElement {
if (checkConflict) this.checkConflict();
return skill;
}
addAdditionalSkill(skill, skills, keep) {
if (this.additionalSkills[skill]) {
if (keep) {
if (typeof this.additionalSkills[skill] == 'string') {
this.additionalSkills[skill] = [this.additionalSkills[skill]];
addAdditionalSkills(skill, skillsToAdd, keep) {
if (typeof skillsToAdd == 'string') skillsToAdd = [skillsToAdd];
if(!Array.isArray(skillsToAdd)){
console.warn(`警告Player[${this.name}].addAdditionalSkills的参数错误应当为技能字符串或数组:`,skillsToAdd);
}
const skillsToRemove = [];
//如果不需要保留原本的additionalSkills则判断要移除的技能并移除这些技能
if (!keep) {
skillsToRemove.addArray(this.getRemovableAdditionalSkills(skill));
}
//创建对应的addSkills的事件
return this.changeSkills(skillsToAdd, skillsToRemove).set('$handle', function(player, skillsToAdd, skillsToRemove){
//先失去先前获得的衍生技能
if (skillsToRemove.length>0) {
game.log(player, '失去了技能', ...skillsToRemove.map(i => {
return '#g【' + get.translation(i) + '】';
}));
player.removeSkill(skillsToRemove);
}
//再获得新的衍生技能
if (skillsToAdd.length>0) {
game.log(player, '获得了技能', ...skillsToAdd.map(i => {
return '#g【' + get.translation(i) + '】';
}));
if (!Array.isArray(player.additionalSkills[skill])) player.additionalSkills[skill] = [];
for (var i = 0; i < skillsToAdd.length; i++) {
player.addSkill(skillsToAdd[i], null, true, true);
player.additionalSkills[skill].push(skillsToAdd[i]);
}
player.checkConflict();
}
else {
this.removeAdditionalSkill(skill);
this.additionalSkills[skill] = [];
}
_status.event.clearStepCache();
});
}
addAdditionalSkill(skill, skillsToAdd, keep) {
if (typeof skillsToAdd == 'string') skillsToAdd = [skillsToAdd];
if(!Array.isArray(skillsToAdd)){
console.warn(`警告Player[${this.name}].addAdditionalSkill的参数错误应当为技能字符串或数组:`,skillsToAdd);
}
else {
this.additionalSkills[skill] = [];
const skillsToRemove = [];
//如果不需要保留原本的additionalSkills则判断要移除的技能并移除这些技能
if (!keep) {
skillsToRemove.addArray(this.getRemovableAdditionalSkills(skill));
}
if (typeof skills == 'string') {
skills = [skills];
}
for (var i = 0; i < skills.length; i++) {
this.addSkill(skills[i], null, true, true);
//this.skills.remove(skills[i]);
this.additionalSkills[skill].push(skills[i]);
this.removeSkill(skillsToRemove);
//然后处理获得技能的操作
if (!Array.isArray(this.additionalSkills[skill])) this.additionalSkills[skill] = [];
for (var i = 0; i < skillsToAdd.length; i++) {
this.addSkill(skillsToAdd[i], null, true, true);
this.additionalSkills[skill].push(skillsToAdd[i]);
}
this.checkConflict();
_status.event.clearStepCache();
return this;
}
removeAdditionalSkill(skill, target) {
const player = this;
getRemovableAdditionalSkills(skill, target){
const player = this, removableSkills = [];
if (this.additionalSkills[skill]) {
const additionalSkills = this.additionalSkills[skill];
const hasAnotherSKill = function (skillkey, skill) {
@ -7417,24 +7446,38 @@ export class Player extends HTMLDivElement {
};
if (Array.isArray(additionalSkills) && typeof target == 'string') {
if (additionalSkills.includes(target)) {
additionalSkills.remove(target);
if (!hasAnotherSKill(skill, target)) this.removeSkill(target);
removableSkills.push(target);
}
}
else {
delete this.additionalSkills[skill];
if (typeof additionalSkills == 'string') {
if (!hasAnotherSKill(skill, additionalSkills)) this.removeSkill(additionalSkills);
}
else if (Array.isArray(additionalSkills)) {
const skillsToRemove = additionalSkills.filter(target => !hasAnotherSKill(skill, target));
this.removeSkill(skillsToRemove);
if (Array.isArray(additionalSkills)) {
removableSkills.addArray(additionalSkills.filter(target => !hasAnotherSKill(skill, target)));
}
}
}
return removableSkills;
}
removeAdditionalSkill(skill, target) {
const player = this, skills = this.getRemovableAdditionalSkills(skill, target);
if(skills.length){
player.removeSkill(skills);
if (player.additionalSkills[skill]&&player.additionalSkills[skill].length) delete player.additionalSkills[skill];
}
_status.event.clearStepCache();
return this;
}
removeAdditionalSkills(skill, target) {
const player = this, skills = this.getRemovableAdditionalSkills(skill, target);
if(skills.length){
return player.changeSkills([], skills).set('$handle', function(player, addSkills, removeSkills){
game.log(player, '失去了技能', ...removeSkills.map(i => {
return '#g【' + get.translation(i) + '】';
}));
player.removeSkill(skills);
if (player.additionalSkills[skill]&&player.additionalSkills[skill].length) delete player.additionalSkills[skill];
});
}
}
awakenSkill(skill, nounmark) {
if (!nounmark) this.unmarkSkill(skill);
this.disableSkill(skill + '_awake', skill);
@ -7674,6 +7717,37 @@ export class Player extends HTMLDivElement {
}
return skill;
}
addTempSkills(skillsToAdd, expire, checkConflict){
//请注意该方法的底层实现并非tempSkill而是additionalSkills和player.when
if (typeof skillsToAdd == 'string') skillsToAdd = [skillsToAdd];
if(!Array.isArray(skillsToAdd) || !skillsToAdd.length){
console.warn(`警告Player[${this.name}].addAdditionalSkills的参数错误应当为技能字符串或非空数组:`,skillsToAdd);
}
//确定技能要被移除的时机
if (!expire) expire = { global: ['phaseAfter', 'phaseBeforeStart'] };
else if (typeof expire == 'string' || Array.isArray(expire)) expire = { global: expire };
this.changeSkills(skillsToAdd, []).set('$handle', function(player, addSkills, removeSkills){
if(addSkills.length){
game.log(player, '获得了技能', ...addSkills.map(i => {
return '#g【' + get.translation(i) + '】';
}));
let skillName;
//生成该TempSkills对应的ID
do {
skillName = 'player_tempSkills_' + Math.random().toString(36).slice(-8);
} while (player.additionalSkills[skillName] != null);
player.addAdditionalSkill(skillName, skillsToAdd);
player.when(expire).assign({
firstDo: true,
priority: Infinity,
}).vars({
skillName
}).then(() => {
player.removeAdditionalSkills(skillName);
});
}
});
}
addTempSkill(skill, expire, checkConflict) {
if (Array.isArray(skill)) {
for (var i = 0; i < skill.length; i++) {