webxoss-core/Mask.js
2016-11-09 23:18:40 +08:00

79 lines
No EOL
2 KiB
JavaScript

'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;
}
effect.disabled = false;
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 {
if (!reset && inArr(this.prop,Card.abilityProps)) {
// 不能获得新能力
if (target.canNotGainAbility) return;
if (target.player && target.player.canNotGainAbility) return;
}
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;