1
0
Fork 0

handle coin && rise

This commit is contained in:
WEBXOSS 2017-02-20 23:13:39 +08:00
parent bc5244044b
commit 1d28364349
3 changed files with 138 additions and 23 deletions

79
Card.js
View file

@ -95,6 +95,9 @@ function Card (game,player,zone,pid,side) {
this.sideB = info.sideB? new Card(game,player,zone,info.sideB,this) : null;
}
// Lostorage
this.rise = info.rise;
// 杂项
this.effectFilters = [];
this.registeredEffects = [];
@ -106,7 +109,8 @@ function Card (game,player,zone,pid,side) {
// 时点
this.onMove = new Timming(game);
this.onEnterField = new Timming(game);
this.onLeaveField = new Timming(game);
this.onLeaveField = new Timming(game); // 常时效果中「离场时」的时点
this.onLeaveField2 = new Timming(game); // 包括被 rise 等而成为卡垫的时点
this.onBurst = new Timming(game);
this.onAttack = new Timming(game);
this.onStartUp = new Timming(game);
@ -179,7 +183,7 @@ Card.prototype.cookEffect = function (rawEffect,type,offset) {
};
Card.prototype.setupConstEffects = function () {
this.constEffects.forEach(function (eff) {
this.constEffects.forEach(function (eff,idx) {
var createTimming,destroyTimming,once;
if (eff.duringGame) {
createTimming = null;
@ -191,9 +195,20 @@ Card.prototype.setupConstEffects = function () {
once = eff.once;
} else {
createTimming = this.onEnterField;
destroyTimming = this.onLeaveField;
destroyTimming = this.onLeaveField2;
once = false;
}
var action = eff.action
if (eff.auto) {
action = function (set,add) {
var effect = this.game.newEffect({
source: this,
description: this.cid+'-'+'const-'+idx,
actionAsyn: eff.actionAsyn,
});
add(this,eff.auto,effect);
};
}
this.game.addConstEffect({
source: this,
createTimming: createTimming,
@ -202,7 +217,7 @@ Card.prototype.setupConstEffects = function () {
cross: !!eff.cross,
fixed: !!eff.fixed,
condition: eff.condition,
action: eff.action
action: action,
},true);
},this);
};
@ -312,6 +327,14 @@ Card.prototype.canSummon = function () {
Card.prototype.canSummonWith = function (signis) {
// 类型
if (this.type !== 'SIGNI') return false;
// rise
var riseTargets = []
if (this.rise) {
riseTargets = signis.filter(function (signi) {
return this.rise(signi)
},this)
if (!riseTargets.length) return false;
}
// <绿罗植 世界树>
if (this.player.canNotUseColorlessSigni) {
if (this.hasColor('colorless')) {
@ -328,16 +351,24 @@ Card.prototype.canSummonWith = function (signis) {
// 等级限制
if (this.level > this.player.lrig.level) return false;
// SIGNI 数量限制
if (signis.length >= this.player.getSigniAmountLimit()) {
var length = signis.length;
if (this.rise) length--;
if (length >= this.player.getSigniAmountLimit()) {
return false;
}
// 界限限制
var totalLevel = signis.reduce(function (total,signi) {
return total + signi.level;
},this.level);
if (this.rise) {
// rise 减去等级最高的目标即可
totalLevel -= Math.max.apply(Math,riseTargets.map(function (signi) {
return signi.level;
}));
}
if (totalLevel > this.player.lrig.limit) return false;
// 召唤区限制
var zones = this.player.getSummonZones(signis);
var zones = this.player.getSummonZones(signis,this.rise);
if (!zones.length) return false;
// 结束
return true;
@ -750,6 +781,8 @@ Card.prototype.moveTo = function (zone,arg) {
var leaveFieldEvent = null;
var lrigChangeEvent = null;
var charm = null;
/* 处理离开区域逻辑 */
if (card.zone.name === 'HandZone') {
// 离开手牌
removeFromArr(card,card.player.hands);
@ -757,6 +790,7 @@ Card.prototype.moveTo = function (zone,arg) {
// 离开 SigniZone
if (inArr(card,card.player.signis)) {
// 是 SIGNI
// 以下代码 rise 里复用了,虽然说 DRY 原则,但这里也不太好抽离,养肥了再抽吧(
leaveFieldEvent = moveEvent;
card.frozen = false;
card.fieldData = {};
@ -774,15 +808,36 @@ Card.prototype.moveTo = function (zone,arg) {
}
}
}
/* 处理进入区域逻辑 */
if (zone.name === 'HandZone') {
// 进入手牌
zone.player.hands.push(card);
} else if (zone.name === 'SigniZone') {
if (card.zone.name !== 'SigniZone' || zone.player !== card.player) {
// 进入 SIGNI 区
if (zone.getActualCards().length) {
// 放置到 SIGNI 下面的卡
// rise
if (card.rise) {
// 被 rise 的卡“离场”
signi = zone.getActualCards()[0];
removeFromArr(signi,signi.player.signis);
signi.frozen = false;
signi.fieldData = {};
signi.fieldTurnData = {};
charm = signi.charm;
signi.charm = null;
signi.onLeaveField2.trigger({});
// 出场
arg.bottom = false;
enterFieldEvent = moveEvent;
card.player.signis.push(card);
} else {
// 放置到 SIGNI 下面的卡
// (目前不用处理)
}
} else {
// 进入 SigniZone
// 出场
enterFieldEvent = moveEvent;
zone.player.signis.push(card);
}
@ -882,6 +937,7 @@ Card.prototype.moveTo = function (zone,arg) {
} else if (leaveFieldEvent) {
// card.player.onSignisChange.trigger();
card.onLeaveField.trigger(leaveFieldEvent);
card.onLeaveField2.trigger(leaveFieldEvent);
card.player.onSigniLeaveField.trigger(leaveFieldEvent);
// SIGNI 离场时,下面的卡送入废弃区,
// 此处理在块结束时执行。
@ -896,7 +952,7 @@ Card.prototype.moveTo = function (zone,arg) {
} else if (lrigChangeEvent) {
// card.player.onLrigChange.trigger(lrigChangeEvent);
var oldLrig = lrigChangeEvent.oldLrig;
if (oldLrig) oldLrig.onLeaveField.trigger();
if (oldLrig) oldLrig.onLeaveField2.trigger();
card.onEnterField.trigger(enterFieldEvent);
if (!(arg.dontTriggerStartUp || card.player.lrigStartUpBanned)) {
card.onStartUp.trigger(enterFieldEvent);
@ -1280,10 +1336,7 @@ Card.prototype.banishAsyn = function (arg) {
// };
Card.prototype.summonAsyn = function (optional,dontTriggerStartUp,down) {
var zones = this.player.signiZones.filter(function (zone) {
return (zone.getActualCards().length === 0);
},this);
if (!this.canSummon() || !zones.length) return Callback.immediately();
if (!this.canSummon()) return Callback.immediately();
return Callback.immediately().callback(this,function () {
if (optional) {
return this.player.selectOptionalAsyn('SUMMON_SIGNI',[this]);

View file

@ -58445,7 +58445,7 @@ var CardInfo = {
this.player.signis.forEach(function (signi) {
this.game.addConstEffect({
source: signi,
destroyTimming: [signi.onLeaveField,this.game.phase.onTurnEnd],
destroyTimming: [signi.onLeaveField2,this.game.phase.onTurnEnd],
condition: function () {
var opposingSigni = this.getOpposingSigni();
if (!opposingSigni) return false;
@ -124590,7 +124590,7 @@ var CardInfo = {
"【起】《ターン1回》《赤》《赤》《赤》:ターン終了時まで、あなたの《ライズアイコン》を持つシグニ1体は「このシグニが正面にあるシグニ1体をバニッシュしたとき、このシグニをアップする。」を得る。"
],
actionEffectTexts_zh_CN: [
"【起】《1回合1次》【红】【红】【红】直到回合结束为止你的1只持有【】的SIGNI获得「这只SIGNI对面的SIGNI被驱逐时将这只SIGNI竖置」。"
"【起】《1回合1次》【红】【红】【红】直到回合结束为止你的1只持有【Rise】的SIGNI获得「这只SIGNI对面的SIGNI被驱逐时将这只SIGNI竖置」。"
],
actionEffectTexts_en: [
"[Action] [1/Turn] [Red] [Red] [Red]: Until end of turn, 1 of your SIGNI with Rise gets \"When the SIGNI in front of this SIGNI is banished, up this SIGNI.\"."
@ -124600,7 +124600,7 @@ var CardInfo = {
costRed: 3,
actionAsyn: function () {
var filter = function (card) {
return card.hasBurst();
return card.rise;
}
return this.player.selectSelfSigniAsyn(filter).callback(this,function (card) {
if (!card) return;
@ -125548,7 +125548,51 @@ var CardInfo = {
"Banish 1 of your <Valor> SIGNI with Rise. If you do, banish 1 of your opponent's SIGNI with power 12000 or less.",
],
spellEffect: [{
// TODO...
getTargets: function () {
return this.player.signis.filter(function (signi) {
return !signi.rise && signi.hasClass('武勇');
},this);
},
actionAsyn: function (card) {
return card.banishAsyn().callback(this,function (succ) {
if (!succ) return;
var filter = function (card) {
return card.rise && card.hasClass('武勇');
};
return this.player.seekAsyn(filter,1);
});
}
},{
getTargetAdvancedAsyn: function () {
var targets = [];
var pSignis = this.player.signis.filter(function (signi) {
return signi.rise && signi.hasClass('武勇');
});
var oSignis = this.player.opponent.signis.filter(function (signi) {
return signi.power <= 12000;
},this);
return this.player.selectTargetOptionalAsyn(pSignis).callback(this,function (targetA) {
if (!targetA) return;
targets.push(targetA);
return this.player.selectTargetAsyn(oSignis).callback(this,function (targetB) {
if (!targetB) return;
targets.push(targetB);
});
}).callback(this,function () {
return targets;
});
},
actionAsyn: function (targets) {
var targetA = targets[0];
var targetB = targets[1];
if (!inArr(targetA,this.player.signis)) return;
return targetA.banishAsyn().callback(this,function (succ) {
if (!succ) return;
if (!inArr(targetB,this.player.opponent.signis)) return;
if (targetB.power > 12000) return;
return targetB.banishAsyn();
});
}
}],
},
"2018": {

View file

@ -28,6 +28,7 @@ function Player (game,io,mainDeck,lrigDeck) {
// 然后在调用堆栈的最后将整个队列发送.
this.messagePacks = []; // 用于保存录像.
this.rebuildCount = 0;
this.coin = 0;
// 快捷方式
this.hands = []; // 手牌
@ -404,7 +405,7 @@ Player.prototype.summonSigniAsyn = function () {
return Callback.never();
}
return this.selectAsyn('SUMMON_SIGNI',cards).callback(this,function (card) {
return this.selectSummonZoneAsyn(true).callback(this,function (zone) {
return this.selectSummonZoneAsyn(true,card.rise).callback(this,function (zone) {
if (!zone) return;
return this.game.blockAsyn(this,function () {
card.moveTo(zone);
@ -459,8 +460,8 @@ Player.prototype.summonResonaAsyn = function (card) {
});
};
Player.prototype.selectSummonZoneAsyn = function (optional) {
var zones = this.getSummonZones();
Player.prototype.selectSummonZoneAsyn = function (optional,rise) {
var zones = this.getSummonZones(null,rise);
if (!zones.length) {
debugger;
return Callback.immediately(null);
@ -469,13 +470,17 @@ Player.prototype.selectSummonZoneAsyn = function (optional) {
return this.selectAsyn('SUMMON_SIGNI_ZONE',zones);
};
Player.prototype.getSummonZones = function (signis) {
Player.prototype.getSummonZones = function (signis,rise) {
if (!signis) signis = this.signis;
var forcedZones = [];
var zones = this.signiZones.filter(function (zone,idx) {
if (zone.disabled) return false;
var signi = zone.getActualCards()[0];
if (signi && inArr(signi,signis)) return false;
if (rise) {
if (!signi || !rise(signi)) return false;
} else {
if (signi && inArr(signi,signis)) return false;
}
var opposingSigni = this.opponent.signiZones[2-idx].getActualCards()[0];
if (opposingSigni && opposingSigni.forceSummonZone) {
forcedZones.push(zone);
@ -1385,7 +1390,7 @@ Player.prototype.needEner = function (obj) {
if (obj.costChange) {
obj = obj.costChange();
}
var costs = [obj.costColorless,obj.costWhite,obj.costBlack,obj.costRed,obj.costBlue,obj.costGreen];
var costs = [obj.costColorless,obj.costWhite,obj.costBlack,obj.costRed,obj.costBlue,obj.costGreen,costCoin];
return costs.some(function (cost) {
return cost > 0;
});
@ -1665,6 +1670,7 @@ Player.prototype.enoughCost = function (obj) {
if (obj.costChange) {
obj = obj.costChange();
}
if (obj.costCoin && obj.costCoin >= this.coin) return false;
if (!this.enoughEner(obj)) return false;
if (obj.costDown && obj.source && !obj.source.isUp) return false;
if (obj.costCondition && obj.source) {
@ -1821,6 +1827,11 @@ Player.prototype.payCostAsyn = function (obj,cancelable) {
if (obj.costDown && obj.source) {
obj.source.down();
}
// Coin
if (obj.costCoin) {
this.coin -= obj.costCoin
if (this.coin < 0) this.coin = 0
}
// 其它
if (obj.costAsyn) {
if (obj.source) return obj.costAsyn.call(obj.source);
@ -2203,6 +2214,13 @@ Player.prototype.setCrossPair = function () {
pair.crossed = [card,pair];
};
Player.prototype.gainCoins = function(count) {
this.coin += count;
if (this.coin > 5) {
this.coin = 5;
}
};
// For test:
Player.prototype.matchCard = function (arg) {