添加事件化版本的addTempSkills,addAdditionalSkills和removeAdditionalSkills
This commit is contained in:
parent
33c7439149
commit
bbfa0e47e9
|
@ -17639,10 +17639,7 @@ game.import('character',function(lib,game,ui,get,ai,_status){
|
||||||
'step 1'
|
'step 1'
|
||||||
if(result.bool){
|
if(result.bool){
|
||||||
var skills=lib.skill.junkyuheng.derivation.randomGets(result.cards.length);
|
var skills=lib.skill.junkyuheng.derivation.randomGets(result.cards.length);
|
||||||
player.changeSkills(skills,[]).set('$handle',(player,skills)=>{
|
player.addAdditionalSkills('junkyuheng',skills);
|
||||||
player.addAdditionalSkill('junkyuheng',skills);
|
|
||||||
game.log(player,'获得了以下技能:','#g'+get.translation(skills));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
group:'junkyuheng_remove',
|
group:'junkyuheng_remove',
|
||||||
|
@ -17655,13 +17652,10 @@ game.import('character',function(lib,game,ui,get,ai,_status){
|
||||||
filter(event,player){
|
filter(event,player){
|
||||||
return player.additionalSkills.junkyuheng&&player.additionalSkills.junkyuheng.length>0;
|
return player.additionalSkills.junkyuheng&&player.additionalSkills.junkyuheng.length>0;
|
||||||
},
|
},
|
||||||
content(){
|
async content(event,trigger,player){
|
||||||
const skills = player.additionalSkills.junkyuheng;
|
const skills = player.additionalSkills.junkyuheng;
|
||||||
player.draw(skills.length);
|
await player.draw(skills.length);
|
||||||
player.changeSkills([],skills).set('$handle',(player,addSkills,removeSkills)=>{
|
await player.removeAdditionalSkills('junkyuheng');
|
||||||
game.log(player,'失去了以下技能:','#g'+get.translation(removeSkills));
|
|
||||||
for(let skill of removeSkills) player.removeAdditionalSkill('junkyuheng',skill);
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -17728,7 +17722,6 @@ game.import('character',function(lib,game,ui,get,ai,_status){
|
||||||
'step 2'
|
'step 2'
|
||||||
if(result.bool){
|
if(result.bool){
|
||||||
var skills=result.links;
|
var skills=result.links;
|
||||||
game.log(player,'失去了以下技能:','#g'+get.translation(skills));
|
|
||||||
player.removeSkills(skills.slice(0));
|
player.removeSkills(skills.slice(0));
|
||||||
}
|
}
|
||||||
var list=lib.skill.junkdili.derivation;
|
var list=lib.skill.junkdili.derivation;
|
||||||
|
|
|
@ -24791,8 +24791,7 @@ game.import('character',function(lib,game,ui,get,ai,_status){
|
||||||
}
|
}
|
||||||
if(event.num>1) player.draw(2);
|
if(event.num>1) player.draw(2);
|
||||||
if(event.num>2){
|
if(event.num>2){
|
||||||
player.addTempSkill('lingren_jianxiong',{player:'phaseBegin'});
|
player.addTempSkills(['lingren_jianxiong','lingren_xingshang'],{player:'phaseBegin'});
|
||||||
player.addTempSkill('lingren_xingshang',{player:'phaseBegin'});
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ai:{
|
ai:{
|
||||||
|
@ -25991,7 +25990,7 @@ game.import('character',function(lib,game,ui,get,ai,_status){
|
||||||
},
|
},
|
||||||
translate:{
|
translate:{
|
||||||
"xinfu_lingren":"凌人",
|
"xinfu_lingren":"凌人",
|
||||||
"xinfu_lingren_info":"每回合限一次。当你于出牌阶段内使用带有「伤害」标签的基本牌或普通锦囊牌指定目标后,你可以猜测其中的一个目标的手牌中是否有基本牌,锦囊牌或装备牌。若你猜中的项目数:≥1,此牌对该角色的伤害+1;≥2,你摸两张牌;≥3,你获得技能〖奸雄〗和〖行殇〗直到下回合开始。",
|
"xinfu_lingren_info":"每回合限一次。当你于出牌阶段内使用带有「伤害」标签的基本牌或普通锦囊牌指定目标后,你可以猜测其中的一个目标的手牌中是否有基本牌,锦囊牌或装备牌。若你猜中的项目数:≥1,此牌对该角色的伤害+1;≥2,你摸两张牌;≥3,你获得技能〖奸雄〗和〖行殇〗直到你的下回合开始。",
|
||||||
"lingren_adddamage":"凌人",
|
"lingren_adddamage":"凌人",
|
||||||
"lingren_adddamage_info":"",
|
"lingren_adddamage_info":"",
|
||||||
"lingren_jianxiong":"奸雄",
|
"lingren_jianxiong":"奸雄",
|
||||||
|
|
|
@ -602,7 +602,7 @@ export class Player extends HTMLDivElement {
|
||||||
scope = _scope;
|
scope = _scope;
|
||||||
if (skill.contentFuns.length > 0) createContent();
|
if (skill.contentFuns.length > 0) createContent();
|
||||||
return this;
|
return this;
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -7377,35 +7377,64 @@ export class Player extends HTMLDivElement {
|
||||||
if (checkConflict) this.checkConflict();
|
if (checkConflict) this.checkConflict();
|
||||||
return skill;
|
return skill;
|
||||||
}
|
}
|
||||||
addAdditionalSkill(skill, skills, keep) {
|
addAdditionalSkills(skill, skillsToAdd, keep) {
|
||||||
if (this.additionalSkills[skill]) {
|
if (typeof skillsToAdd == 'string') skillsToAdd = [skillsToAdd];
|
||||||
if (keep) {
|
if(!Array.isArray(skillsToAdd)){
|
||||||
if (typeof this.additionalSkills[skill] == 'string') {
|
console.warn(`警告:Player[${this.name}].addAdditionalSkills的参数错误,应当为技能字符串或数组:`,skillsToAdd);
|
||||||
this.additionalSkills[skill] = [this.additionalSkills[skill]];
|
|
||||||
}
|
}
|
||||||
|
const skillsToRemove = [];
|
||||||
|
//如果不需要保留原本的additionalSkills,则判断要移除的技能,并移除这些技能
|
||||||
|
if (!keep) {
|
||||||
|
skillsToRemove.addArray(this.getRemovableAdditionalSkills(skill));
|
||||||
}
|
}
|
||||||
else {
|
//创建对应的addSkills的事件
|
||||||
this.removeAdditionalSkill(skill);
|
return this.changeSkills(skillsToAdd, skillsToRemove).set('$handle', function(player, skillsToAdd, skillsToRemove){
|
||||||
this.additionalSkills[skill] = [];
|
//先失去先前获得的衍生技能
|
||||||
|
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]);
|
||||||
}
|
}
|
||||||
else {
|
player.checkConflict();
|
||||||
this.additionalSkills[skill] = [];
|
|
||||||
}
|
}
|
||||||
if (typeof skills == 'string') {
|
_status.event.clearStepCache();
|
||||||
skills = [skills];
|
});
|
||||||
}
|
}
|
||||||
for (var i = 0; i < skills.length; i++) {
|
addAdditionalSkill(skill, skillsToAdd, keep) {
|
||||||
this.addSkill(skills[i], null, true, true);
|
if (typeof skillsToAdd == 'string') skillsToAdd = [skillsToAdd];
|
||||||
//this.skills.remove(skills[i]);
|
if(!Array.isArray(skillsToAdd)){
|
||||||
this.additionalSkills[skill].push(skills[i]);
|
console.warn(`警告:Player[${this.name}].addAdditionalSkill的参数错误,应当为技能字符串或数组:`,skillsToAdd);
|
||||||
}
|
}
|
||||||
|
const skillsToRemove = [];
|
||||||
|
//如果不需要保留原本的additionalSkills,则判断要移除的技能,并移除这些技能
|
||||||
|
if (!keep) {
|
||||||
|
skillsToRemove.addArray(this.getRemovableAdditionalSkills(skill));
|
||||||
|
}
|
||||||
|
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();
|
this.checkConflict();
|
||||||
_status.event.clearStepCache();
|
_status.event.clearStepCache();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
removeAdditionalSkill(skill, target) {
|
getRemovableAdditionalSkills(skill, target){
|
||||||
const player = this;
|
const player = this, removableSkills = [];
|
||||||
if (this.additionalSkills[skill]) {
|
if (this.additionalSkills[skill]) {
|
||||||
const additionalSkills = this.additionalSkills[skill];
|
const additionalSkills = this.additionalSkills[skill];
|
||||||
const hasAnotherSKill = function (skillkey, skill) {
|
const hasAnotherSKill = function (skillkey, skill) {
|
||||||
|
@ -7417,24 +7446,38 @@ export class Player extends HTMLDivElement {
|
||||||
};
|
};
|
||||||
if (Array.isArray(additionalSkills) && typeof target == 'string') {
|
if (Array.isArray(additionalSkills) && typeof target == 'string') {
|
||||||
if (additionalSkills.includes(target)) {
|
if (additionalSkills.includes(target)) {
|
||||||
additionalSkills.remove(target);
|
removableSkills.push(target);
|
||||||
if (!hasAnotherSKill(skill, target)) this.removeSkill(target);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
delete this.additionalSkills[skill];
|
if (Array.isArray(additionalSkills)) {
|
||||||
if (typeof additionalSkills == 'string') {
|
removableSkills.addArray(additionalSkills.filter(target => !hasAnotherSKill(skill, target)));
|
||||||
if (!hasAnotherSKill(skill, additionalSkills)) this.removeSkill(additionalSkills);
|
|
||||||
}
|
|
||||||
else if (Array.isArray(additionalSkills)) {
|
|
||||||
const skillsToRemove = additionalSkills.filter(target => !hasAnotherSKill(skill, target));
|
|
||||||
this.removeSkill(skillsToRemove);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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();
|
_status.event.clearStepCache();
|
||||||
return this;
|
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) {
|
awakenSkill(skill, nounmark) {
|
||||||
if (!nounmark) this.unmarkSkill(skill);
|
if (!nounmark) this.unmarkSkill(skill);
|
||||||
this.disableSkill(skill + '_awake', skill);
|
this.disableSkill(skill + '_awake', skill);
|
||||||
|
@ -7674,6 +7717,37 @@ export class Player extends HTMLDivElement {
|
||||||
}
|
}
|
||||||
return skill;
|
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) {
|
addTempSkill(skill, expire, checkConflict) {
|
||||||
if (Array.isArray(skill)) {
|
if (Array.isArray(skill)) {
|
||||||
for (var i = 0; i < skill.length; i++) {
|
for (var i = 0; i < skill.length; i++) {
|
||||||
|
|
Loading…
Reference in New Issue