1
0
Fork 0
webxoss-fixed/Mask.js

79 lines
2 KiB
JavaScript
Raw Normal View History

2016-10-23 07:56:45 +02:00
'use strict';
function Mask (target,prop,value,forced) {
this.target = target;
this.prop = prop;
this.value = value;
this.forced = forced;
if ((prop === 'onBurst') && this.value) {
this.value.isBurst = true;
}
}
Mask.prototype.set = function (reset) {
var target = this.target;
var item = target[this.prop];
if (item === undefined) {
debugger;
console.warn('Mask.set(): target.pid:%s,this.prop:%s,this.value:%s',target.pid,this.prop,this.value);
} else if (isObj(item) && (item.constructor === Timming)) {
// item.effects.length = 0;
if (reset) {
item.effects.length = 0;
return;
}
var timming = item;
var effect = this.value;
var source = effect.source;
if (source.canNotGainAbility || source.player.canNotGainAbility) {
// 不能获得新能力
return;
}
2016-11-09 16:18:40 +01:00
effect.disabled = false;
2016-10-23 07:56:45 +02:00
timming.effects.push(effect);
effect.source.registeredEffects.push(effect);
return;
} else if (isArr(item)) {
target[this.prop] = this.value.slice();
} else if (this.prop === 'abilityLost') {
target.abilityLost = this.value;
if (!target.abilityLost) return;
Card.abilityProps.forEach(function (prop) {
target[prop] = false;
},this);
target.registeredEffects.forEach(function (effect) {
effect.disabled = true;
},this);
} else {
2016-10-31 16:31:04 +01:00
if (!reset && inArr(this.prop,Card.abilityProps)) {
2016-10-23 07:56:45 +02:00
// 不能获得新能力
if (target.canNotGainAbility) return;
if (target.player && target.player.canNotGainAbility) return;
2016-10-23 07:56:45 +02:00
}
target[this.prop] = this.value;
}
};
Mask.prototype.add = function (reset) {
var item = this.target[this.prop];
if (isArr(item)) {
var arr = item;
arr.push(this.value);
return;
}
if (isObj(item) && (item.constructor === Timming)) {
return;
}
this.target[this.prop] += this.value;
};
Mask.prototype.checkFilter = function (source) {
if (this.forced) return true;
var target = this.target;
if (!target.isEffectFiltered) return true;
return !target.isEffectFiltered(source);
};
global.Mask = Mask;