1
0
Fork 0
webxoss-fixed/Mask.js

81 lines
2 KiB
JavaScript
Raw Normal View History

2016-10-23 07:56:45 +02:00
'use strict';
2016-11-17 15:13:19 +01:00
function Mask (source,target,prop,value,forced) {
this.source = source;
2016-10-23 07:56:45 +02:00
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) && (this.prop.indexOf('_') !== 0)) {
2016-10-23 07:56:45 +02:00
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;
2016-11-17 15:13:19 +01:00
// 不能获得新能力
if (!source.canGainAbility(this.source)) {
2016-10-23 07:56:45 +02:00
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-11-17 15:13:19 +01:00
if (!reset && target.player && inArr(this.prop,Card.abilityProps)) {
2016-10-23 07:56:45 +02:00
// 不能获得新能力
if (!target.canGainAbility(this.source)) {
2016-11-17 15:13:19 +01:00
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;